java - Formatted Output With Variable Spacing -
is there feature supports using variable in flag of javas printf method, example
printf("%nd", 12);
where n variable?
i want specify spacing outside of printf method, example
int n = 5; system.out.printf("%nd", 12);
instead of following
system.out.printf("%5d", 12);
alternatively, there built-in feature similar that?
you don't need pass spacing in part of data.
can build format string on fly in printf()
statement so:
int n = 5; system.out.printf("%"+n+"d", 12);
Comments
Post a Comment