Gar*_*eth 4 java eclipse string-formatting
我正在寻找一种快速简单的方法来将int格式化为带有两个前导零的字符串.我发现这个/sf/answers/306413621/答案,它看起来像我需要的.所以我这样实现了它
int i = 34; //could be any value but you get the idea
String.format("%03d", i);
Run Code Online (Sandbox Code Playgroud)
但是,Eclipse似乎对于String.format需要Object[]第二个参数这一事实感到呻吟.这里发生了什么?
如果要打印值i,可以使用:
System.out.printf("%03d", i);
Run Code Online (Sandbox Code Playgroud)
代替
System.out.println(String.format("%03d", i));
Run Code Online (Sandbox Code Playgroud)
编辑:
此外,我在Java 6中尝试了您的代码,但它无法正常工作.所以,我使用了printf().
喔.抱歉!我清理了项目并且工作正常.
我正在使用Java 6和Eclipse Helios.
| 归档时间: |
|
| 查看次数: |
1818 次 |
| 最近记录: |