Java – how to print two positions correctly using the zero padding flag in a print statement
•
Java
What if you want to print with zero pad
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
}
Solution
int month,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
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
