• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having 001, 002, etc rather than 1, 2

 
Ryan Akim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


See, I need every "|" to line up with each other, it just looks better, and my professor will, indeed care.
But the first range is "1-10" and the second is "11-20"... so it causes this problem:

1-10 |
11-20 |
21-30 |
...
91-100 |

If I could have 002, 003...010, 091, etc, it would fix this, wouldn't it?
I have no idea how to achieve this, though.
Help greatly appreciated.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use System.out.printf(String format, Object parameter)

The format string something like this "%03", will help, to print integer in the format "001", 039", etc..

To know more about from where I derived the format string, look here.

HTH and Welcome to JavaRanch !!

 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This Java Tutorials section may be easier to understand.
 
Ryan Akim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I will try it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic