Java中System.out.printf引數傳遞錯誤分析與修正
阿新 • • 發佈:2019-01-22
在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,僅供參考。