为什么通过简单调用printf会出现以下编译错误?我的代码:
import java.util.Scanner;
public class TestCodeBankAccInputs
{
public static void main(String[] args)
{
String displayName = "Bank of America Checking";
int balance = 100;
System.out.printf("%s has %7.2f", displayName, balance);
}
}
Run Code Online (Sandbox Code Playgroud)
在编译时我收到以下错误:
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, String, double)
at TestCodeBankAccInputs.main(TestCodeBankAccInputs.java:9)
Run Code Online (Sandbox Code Playgroud)
造成这种情况的原因是什么?如何解决?
在Eclipse中帮助 - >关于提供以下信息:
面向Web开发人员的Eclipse Java EE IDE.
版本:Indigo Release Build id:20110615-0604
我安装的JDK是JDK1.6.0_27
我已经看到有关String.format的类似问题.一些用户建议它可能是构建问题,但看起来我已经更新了版本.
use*_*421 35
检查Compiler compliance level项目的设置是否至少为1.5:
项目>属性> Java编译器
如果Enable project specific settings未设置,请使用Configue Workspace Settings...该页面上的链接检查全局Compiler compliance level.

| 归档时间: |
|
| 查看次数: |
48504 次 |
| 最近记录: |