Eclipse Java printf 问题 PrintStream 不适用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24218802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse Java printf issue PrintStream is not applicable
提问by Ligardian
I'm doing a intro to programming course and I'm having issues with my Eclipse that doesn't seem to want to run printf
in even its simplest form.
我正在做一个编程课程的介绍,我的 Eclipse 出现了问题,它似乎不想以printf
最简单的形式运行。
My code is:
我的代码是:
package Practice;
import java.io.*;
public class Printf {
public static void main(String[] args) throws IOException
{
int num1 = 54;
int num2 = 65;
int sum = num1 + num2;
System.out.printf("Sum of %d and %d is %d.", num1, num2, sum);
}
}
The error is as saying
错误是说
The method
printf(String, Object[])
in the typePrintStream
is not applicable for the arguments(String, int, int, int)
printf(String, Object[])
类型中的方法PrintStream
不适用于参数(String, int, int, int)
I have the Java compiler compliance level set to 1.8 so it should have no issues as I have read in previous posts. Kepler version of Eclipse has had the Java 8 patch applied (so I could comply with 1.8)
我将 Java 编译器合规性级别设置为 1.8,因此它应该没有问题,正如我在之前的帖子中所读到的那样。Eclipse 的 Kepler 版本已经应用了 Java 8 补丁(所以我可以遵守 1.8)
No site I have found has given me any other clues as to what the issue could be?
我发现的任何网站都没有给我任何其他关于问题可能是什么的线索?
采纳答案by Ligardian
Turns out the project folders in Eclipse run on their own properties seperate from the Eclipse main settings .. in order for them to compile on version 1.6/1.7/1.8 you have to change their properties seperatly from the main settings...
原来 Eclipse 中的项目文件夹在它们自己的属性上运行,与 Eclipse 主设置分开......为了让它们在版本 1.6/1.7/1.8 上编译,你必须从主设置中单独更改它们的属性......
Basically instead of going to windows > preferances ... to change and update the compiler version you right click on the project folder in Package Explorer > Properties > Java Compiler then check the Enable project specific settings and then Change the settings below to the compiler compliance level of 1.5 or higher in order for this code above to work.
基本上,不是转到 windows > 首选项 ... 更改和更新编译器版本,您右键单击包资源管理器 > 属性 > Java 编译器中的项目文件夹,然后检查启用项目特定设置,然后将下面的设置更改为编译器合规性1.5 或更高级别才能使上面的代码正常工作。
Why it does that i have no idea makes no sence but it at least works now :)
为什么我不知道这样做没有意义,但它至少现在有效:)
回答by jhobbie
Try using System.out.format("Sum of %d and %d is %d.", num1, num2, sum);
instead of printf
尝试使用System.out.format("Sum of %d and %d is %d.", num1, num2, sum);
代替printf
回答by srv
right click on project folder -> properties -> java compiler -> mark(Enable project specific settings) -> set compiler compliance level : 1.6 -> enjoy eclipse
右键单击项目文件夹 -> 属性 -> java 编译器 -> 标记(启用项目特定设置) -> 设置编译器合规性级别:1.6 -> 享受 Eclipse