在Eclipse中使用System.out.printf方法进行格式化打印时,如:System.out.printf("%5d", i),
会提示错误描述:The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String,int)
此处的int可以换成其他基本数据类型如double,long等等;
查看printf()方法定义的路径为:java.io.PrintStream.printf(Locale, String, Object...)和java.io.PrintStream.printf(String, Object...),也就是所在的包java.io,类为PrintStream.class。
错误和JDK的本版相关,具体的原因是Java Compiler中Compiler comlicance level的数值太低。将Compiler comlicance level设置为不小于1.5,重新建立工程即可。
方法:Project >> Properties >> Java Compiler >> Compiler comlicance level。
---------------------------
PS:初学Java,仅供参考。