Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - In Java, how to convert the integer type 1 to the character type "01" or "001"?
In Java, how to convert the integer type 1 to the character type "01" or "001"?

Use DecimalFormat to format numbers, and correspondingly you can use SimpleDateFormat to format time

import?java.text.DecimalFormat;

import?java.text. Format;

public?class?$?{

public?static?void?main(String[]?args)?{

int?num? =?1;

Format?f1?=?new?DecimalFormat("000");

System.out.println(f1.format(num));

Format?f2?=?new?DecimalFormat("00");

System.out.println(f2.format(num));

}

p>

}