如果想用零垫打印这个方法怎么做呢
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
}
Run Code Online (Sandbox Code Playgroud)
ZZ *_*der 10
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
}
Run Code Online (Sandbox Code Playgroud)
您可以使用java.util.Formatter或String.format
String.format("%02d", somenumber)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7035 次 |
| 最近记录: |