This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Getting 01 output versus 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting 01 output versus 1" Watch "Getting 01 output versus 1" New topic

Getting 01 output versus 1

Mark Adams

Joined: Nov 23, 2007
Posts: 16
Can anyone please tell me how I can get a double digit output of 01 rather than just 1.

I have an output that looks like this: 1,22,2,45,6
and would like it to look like this: 01,22,02,45,06

I know it someting very silly and can't wait to see the response.

Thank you,

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114

There are several ways to do this.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38472
. . . and what about

System.out.printf("%02d", number);

Even shorter!
I agree. Here's the link:
subject: Getting 01 output versus 1