java – 如何在print语句中使用零填充标志正确打印​​两个位置

如果想用零垫打印这个方法怎么做呢
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
}

解决方法

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
}

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...