方式有两种,如下代码: for (int i = 0; i < 20; i++) { System.out.println(StringUtils.leftPad(i + "", 2, "0")); System.out.println(String.format("%02d", i)); }