I was looking for a quick easy way to format a int into a string with two leading zeros. I found this https://stackoverflow.com/a/4377337/47690 answer and it looked like what I needed. So I implemented it as such
int i = 34; //could be any value but you get the idea
String.format("%03d", i);
But, Eclipse seems to moan about the fact that String.format requires an Object[]
for its second parameter. What is going on here?
If you want to print the value of i
, you can use:
System.out.printf("%03d", i);
instead of
System.out.println(String.format("%03d", i));
EDIT :
Also I tried your code in Java 6 and it did not work. So, I used printf().
Ohh. sorry! I cleaned the project and it worked.
I am using Java 6 and Eclipse Helios.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With