【发布时间】:2011-12-08 03:13:11
【问题描述】:
为什么我通过简单的 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);
}
}
编译时出现以下错误:
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)
这是什么原因造成的,我该如何解决?
版本信息:
Help->About in Eclipse 提供以下信息:
面向 Web 开发人员的 Eclipse Java EE IDE。
版本:Indigo 发布 内部版本号:20110615-0604
我安装的JDK是JDK1.6.0_27
我见过this similar issue regarding String.format。一些用户认为这可能是构建问题,但看起来我已经更新了版本。
【问题讨论】:
标签: java