java – 如何在print语句中使用零填充标志正确打印??两个位置
发布时间:2020-12-15 00:21:38 所属栏目: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;public void printNumeric()
如果想用零垫打印这个方法怎么做呢
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 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |