Java中System.out.printf()参数传递错误解决方案

使用Eclipse时候,都会使用格式化输出语句System.out.printf()方法进行格式化打印时,如:System.out.printf("%s", "nihao"),

会提示错误描述:The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String,object)

此处的string可以换成其他基本数据类型如double,long等等;

查看printf()方法定义的路径为:java.io.PrintStream.printf(Locale, String, Object...)和java.io.PrintStream.printf(String, Object...),在包java.io,类为PrintStream.class。

主要是JDK版本问题,在JDK1.5以后才有的printf方法,通过Java Compiler中Compiler comlicance level的数值太低。将Compiler comlicance level设置为不小于1.5,重新建立工程,在project-properties-java compiler对应箭头位置在1.5以上,就可以完美解决


---------------------------

猜你喜欢

转载自blog.csdn.net/qwe1021647502cmx/article/details/80450567