Inspect the documentation.
What is the type of the argument expected by sqrt()
?
double
What is the type of value returned by sqrt()
?
double
Is sqrt()
a static method?
Yes
If you look further at
the documentation
for sqrt()
you find some details:
Returns the correctly rounded positive square root of a double value. If the argument is NaN or less than zero, the result is NaN.
NaN stands for "Not a Number".
This is a 64-bit pattern that is returned by sqrt()
when its argument is not correct.
Here is an example run of the program:
C:\chap13>java SquareRoot Enter a double: -3 square root : NaN
println()
outputs the
characters "NaN"
when it is given the pattern.
(The actual bit pattern is not character data.)
What does this fragment output:
int x = 9; System.out.println( Math.sqrt( x ) );