Reputation: 557
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
Reputation: 4435
Use String.format
output.println(String.format("Nimi: %s | Keskmine hinne %f | Aine: %s", i.askName(), i.askMedian(), i.askSubject()));
Upvotes: 4
Reputation: 216
Use printf() not println(). println() does not allow text formatting.
Upvotes: 5