Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting 01 output versus 1

 
Mark Adams
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,

Mark
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15435
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways to do this.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and what about

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

Even shorter!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic