我一直在使用Eclipse来学习Java,并且在尝试使用printf
时遇到了问题。
我不断收到错误消息:"The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)"
这是我遇到问题的地方:
public class Lesson25 {
public static void main(String[] args) {
System.out.printf("Total: %d & Quantity: %d\n", 5, 120);
}
}
和
public class Lesson10 {
public static void main(String[] args) {
for (int i=0; i<5; i++) {
System.out.println("The value of i is: " + i);
}
for (int x=5; x>0; x--) {
System.out.printf("The value of n is: %d\n", x);
}
}
}
任何人都可以帮我弄清楚出了什么问题吗? 感谢
答案 0 :(得分:0)
需要配置编译器的合规性级别才能使用所需的Java版本。在Preferences > Java Compiler
中找到此选项。
如果选中[x] Use compliance from execution environment ...
,请按照Java Build Path
链接配置JRE /执行环境。
您的示例被接受,任何合规性大于或等于 1.5 (不支持低于1.5 varargs方法,因此明确提及Object[]
)。