I am not experienced in Java at all and am using a text editor to write code so I can’t see what the problem is (I am running from command line)
I see the error and know what it is but I have no idea how to fix it
System.out.print(String.format("%7d", Math.pow(n,2).toString()));
I also tried without the .toString()
Basically if I print only n it works, but the power function gives me an error probably because of return types, but pow should return a double and the string format %7d is probably also double right?
You are using wrong format specifier..
%dis used for integer.Math.pow()returns primitivedoubleon which you cannot invoketoString()method.Try using
%7swhich is forString, and convert your primitive double value toWrapper type: –But, you don’t need to convert your argument to
String, you can directly usedouble valuewith%f: –