如果想使用零垫打印此方法,您如何这样做
int month, day;
public void printNumeric()
{
System.out.printf("month +"/" +day +" \n");
// i would like the month if it is 5 to be 05 same thing with the day
}
答案 0 :(得分:9)
int month, day;
public void printNumeric()
{
System.out.printf("%02d/%02d\n", month, day);
// i would like the month if it is 5 to be 05 same thing with the day
}
答案 1 :(得分:5)
您可以使用java.util.Formatter或String.format
String.format("%02d", somenumber)
答案 2 :(得分:2)
for (int i=0; i<19; i++)
System.out.format("i: %02d\n", i);