Why do I get the following compilation error with a simple call to printf? My code:
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);
}
}
On compilation I get the following error:
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)
What's causing this and how can I fix it?
Version information:
Help->About in Eclipse gives following information:
Eclipse Java EE IDE for Web Developers.
Version: Indigo Release
Build id: 20110615-0604
The JDK I installed is JDK1.6.0_27
I have seen this similar issue regarding String.format. Some users have suggested it might be a build issue, but looks like I have updated versions.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…