public class TestStringFormat { public static void main(String[] args) { int num = 8; // 0 代表前面补充0 // 8 代表长度为 // d 代表参数为正数型 String str = String.format("%08d", num); System.out.println(str); // 00000008 } }