int k = 7; String formattedString = String.format("%03d", k); System.out.println(formattedString); // 输出 "007"