0
How to print integer value in 2 digits?
I mean Edith is 2,like 01,03,45,99 etc .I want o/p like this can anyone explain
3 Respostas
0
Maybe you can check if the digit is lower than 10, then it will print 0 before the digit.
0
Yea I tried this printing 0 ,but 0 is a string and string cannot be compatible with integer
0
You can use System.out.printf(String format, Object... args).
You give it one formatted String and the values used separated by comma.
Example:
System.out.printf("%02d", x);
%d stands for an integer, %2d means it'll make the printed value at least two characters long and fills up with spaces if needed, %02d will do the same as %2d but will fill up with '0' instead.
More information to printf (and probably a better explanation than mine :P): https://docs.oracle.com/javase/tutorial/java/data/numberformat.html
It's mainly about the format function but printf works the same way.