Java formatting, how do I get a symbol to stick to an int?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Java formatting, how do I get a symbol to stick to an int?



I'm trying to print out a metric to imperial table and the format needs to be very specific.



Using the format string :


System.out.printf("%-2d%-1s|",counter++,"'");



I get the output:
"1 '|"



I need it to be:
"1' |"



Many thanks





System.out.printf("%d%-1s|", counter++, "'");...?
– Reimeus
6 mins ago


System.out.printf("%d%-1s|", counter++, "'");





System.out.printf("%2d%-1s|", 1,"'");?
– Debmalya Biswas
5 mins ago




System.out.printf("%2d%-1s|", 1,"'");





I also need it to be left justified :(
– Michelle Lopes
50 secs ago




2 Answers
2


System.out.printf("%,2d%s|", i, "'");



will create an output like


8'|
9'|
10'|
11'|



I think
System.out.printf("%d%-2s|",counter++,"'");



is what you need






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Future solutions