This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Having 001, 002, etc rather than 1, 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having 001, 002, etc rather than 1, 2" Watch "Having 001, 002, etc rather than 1, 2" New topic
Author

Having 001, 002, etc rather than 1, 2

Ryan Akim
Greenhorn

Joined: Feb 20, 2009
Posts: 5


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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 !!


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
This Java Tutorials section may be easier to understand.
Ryan Akim
Greenhorn

Joined: Feb 20, 2009
Posts: 5
Thank you, I will try it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Having 001, 002, etc rather than 1, 2
 
Similar Threads
loop over array to check for duplicates
Do while error, I'm going crazy
help: java program to convert decimal number to hexadecimal number
Need help with Loops
How close am I in getting this program right?