最佳答案
我想知道是否有可能使用 Java 中的 String.format 方法给出一个零前面的整数?
例如:
1变成001
2变成了002
...
11变成了011
12变成了012
...
526还是526
等等
目前我尝试了以下代码:
String imageName = "_%3d" + "_%s";
for( int i = 0; i < 1000; i++ ){
System.out.println( String.format( imageName, i, "foo" ) );
}
不幸的是,这个数字前面有3个空格。有没有可能在这个数字前面加上零呢?