Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please reply!

 
zoster gibrilian
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to concatenate 8-length() of 0's before a string that has as length: lenght().
In other words i have to write a loop that will print out (if needed!) 0's in front of a string ... in order to make it a 8 charachter string

P.S.
I can not believe that java does not have a function that prints a charachter n-times. Or does it?
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't, but you can easily write your own:
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way, perhaps
String pad = "00000000";
String str = "12345";
str = pad.substring(0,pad.length()-str.length())+str;
System.out.println(str);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic