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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -