Reputation: 4663
Here is the code:
class Root {
public static void main(String[] arguments) {
int number = 225;
System.out.println("The square root of "
+ number
+ " is "
+ Math.sqrt.(number)
);
}
}
I am learning Java from Sam's Teach Yourself Java in 24 hours 6th edition and already in chapter four I found something I can't get to work. The Math.sqrt function is not recognized, so I presume I need to import something to make it work, but the book doesn't mention anything at all and copying the code verbatim from the author's website also doesn't mention it. Also, nothing was mentioned in setting up Netbeans that included changing any options. I am using Netbeans 7.1 which I suspect is the problem. Any workaround? Help?
Upvotes: 3
Views: 753
Reputation: 178431
Math.sqrt.(number)
↑
should be
Math.sqrt(number)
You got an extra dot there.
Upvotes: 13
Reputation: 33
Yes you had used an extra dot Math.sqrt(number) sqrt is an static function in math class ...and remember that java.lan.object package is auto import.strong text
Upvotes: 0
Reputation: 16035
You have an extra dot (.) after "sqrt", change "Math.sqrt.(number)" to "Math.sqrt(number)". Math-class is under the java.lang -package, and nothing under that package needs to be separately imported.
Upvotes: 2