Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

printf formating  RSS feed

 
Domenico Fusco
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I am just learning java and am trying to format my output using printf which is supposed to be able to format the output as desired. I am using fairly simple code such as

double q = 1.0/3.0;
// Print the number with 3 decimal places.
System.out.printf ("1.0/3.0 = %5.3f %n", q);


however I am getting an error saying

The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, double)

yet I have seen code from java tutorials using the printf as shown above.

What am I missing


Thank you
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works fine for me:




Are you using JDK 1.5? The printf method was added in 1.5 so earlier JDK's will not have it.
 
Domenico Fusco
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
you are right there was nothing wrong with the code. I am running JDK 1.5 but I am using Eclipse and my version of eclipse must have some problem with the printf statement. I recompiled in dos and ran it with no problems . Looks like I need a new version of Eclipse.
Always pays to go back to basics.
Thanks again for the help
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15865
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need Eclipse version 3.1 for Java 5.0 support.

Also, when you're using Eclipse 3.1, make sure you set the compiler compliance to 5.0: right-click your project, choose Properties, Java Compiler; check "Enable project specific setings"; choose "5.0" for compiler compliance level.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!