Veske
Veske

Reputation: 557

Having problems with printing out a double

So I have this line of code

output.println("Nimi: %s | Keskmine hinne %f | Aine: %s", i.askName(), i.askMedian(), i.askSubject());

So the the first and last one are strings but the middle one is a double. Now to print a double I know that you have to use %f right? But for some reason Eclipse is giving me this error:

The method println(String) in the type PrintWriter is not applicable for the arguments (String, String, double, String)

What is the problem here? Why is the error even showing like I am trying to use 4 variables here when I am only using 3?

Upvotes: 0

Views: 84

Answers (2)

forgivenson
forgivenson

Reputation: 4435

Use String.format

output.println(String.format("Nimi: %s | Keskmine hinne %f | Aine: %s", i.askName(), i.askMedian(), i.askSubject()));

Upvotes: 4

Max Seo
Max Seo

Reputation: 216

Use printf() not println(). println() does not allow text formatting.

Upvotes: 5

Related Questions