Programmers learn & share
0 votes

Problem :

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

by (6.9k points)   | 76 views

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 (36.1k points)  
2,183 questions
2,487 answers
241 users