Win a copy of Functional Reactive Programming this week in the Other Languages 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
Posts: 15484
43
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: 50225
79
  • 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