简体   繁体   English

月食月神格式打印

[英]eclipse luna format printing

I have downloaded eclipse Luna. 我已经下载了Eclipse Luna。 But the format printing is not working. 但是格式打印不起作用。 let consider the simple code given below: 让我们考虑下面给出的简单代码:

public class Test {
    public static void main(String args[]) {
        int a=4;
        System.out.printf("%d",a);
    }
}

It is showing error message below: 它在下面显示错误消息:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int) 线程“主”中的异常java.lang.Error:未解决的编译问题:PrintStream类型的方法printf(String,Object [])不适用于参数(String,int)

What may be the possible cause and solution? 可能的原因和解决方法是什么?

Your Compiler compliance level might not be correct. 您的Compiler compliance level可能不正确。

You can find it in Eclipse here: Project > Properties > Java Compiler 您可以在Eclipse中找到它:项目>属性> Java编译器

Make sure it's set to 1.5 or higher. 确保将其设置为1.5或更高。

i have got my answer from the comment of @Katja Christiansen. 我从@Katja Christiansen的评论中得到了答案。 the comment has given below, as @Katja Christiansen not write the solution in asnswer for that i am wrriting it here let other can find that the problem has solved.. 注释已在下面给出,因为@Katja Christiansen并没有在解决方案中写解决方案,因为我在这里写了这个解决方案,让其他人可以发现问题已解决。

"Maybe project specific compiler settings are enabled? Open the properties of your Java project, select "Java Compiler" and check if "Enable project specific settings" is enabled and if the selected JDK differs from the Eclipse JDK settings. – Katja Christiansen " “也许已启用特定于项目的编译器设置?打开Java项目的属性,选择“ Java编译器”,并检查是否已启用“启用特定于项目的设置”,以及所选的JDK是否与Eclipse JDK设置不同。– Katja Christiansen。

after trying it, the printf has solved and it solved for all the existing project. 尝试之后,printf已解决,并且已解决所有现有项目。

Thanks @Katja Christiansen for ur cooperation. 感谢@Katja Christiansen与我们的合作。

Try using the format method: 尝试使用format方法:

int a = 4;
System.out.format("%d", a);

I'm using Eclipse Luna and the following main method runs for me: 我正在使用Eclipse Luna并且为我运行了以下main方法:

public class StackOverflow {

    public static void main(String[] args) {
        int a = 4;
        System.out.printf("%d", a);
    }

}

Gives me the output of: 给我输出:

4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM