• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
7 views

Problem :

I am getting bellow error
java.util.illegalformatconversionexception: d != java.lang.double

by (6.9k points)  

1 Answer

0 votes

Solution :

You must have got a format specifier in the wrong section of the printf statement. So it needs to be in the String that is part of the first parameter, before the comma that separates method parameters. 

So not this:

System.out.printf("x = "+x+", y = %d", y);//incorrect

but rather this:

System.out.printf("x = %d, y = %d", x, y);//correct

or for new line:

System.out.printf("x = %d, y = %d%n", x, y); 

Please note in a printf or String.format(...) statement, use %n not \n for new-lines.

by (20.3k points)  
...