i am going threw the java tutorials and on of the projects was to use the computer to find the square root of a number
my code is
class Root {
private static Object math;
public static void main(String[] args) {
int number = 225;
System.out.println("The square root of"
+ number
+ "is"
+ math.sqrt(number)
);
}
}it is not working and i don't know why please help
Offline
This can't work!
Just do this:
public class Root {
public static void main(String[] args) {
int number = 225;
System.out.println("The square root of"
+ number
+ "is"
+ Math.sqrt(number)
);
}
}The "math" Object you made is null.
(=> NullPointerException when you use it)
And java.lang.Math is final, you can't make an instance of it.
Last edited by ZeroLuck (2012-03-31 15:41:02)
Offline
thank you
Offline
if i have anymore problems ill post here
Offline
That's because you re-defined math, which actually should have been Math, which you shouldn't have redefined..
Offline