java – 如何在print语句中使用零填充标志正确打印两个位置
发布时间:2020-05-24 15:03:08 所属栏目:Java 来源:互联网
导读:如果想用零垫打印这个方法怎么做呢 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;
|
如果想用零垫打印这个方法怎么做呢 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/%02dn",month,day);
// i would like the month if it is 5 to be 05 same thing with the day
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
