Java Programming - Java.lang Class - Discussion

Discussion Forum : Java.lang Class - Finding the output (Q.No. 14)
14.
What will be the output of the program?
public class SqrtExample 
{
    public static void main(String [] args) 
    {
        double value = -9.0;
        System.out.println( Math.sqrt(value));
    }
}
3.0
-3.0
NaN
Compilation fails.
Answer: Option
Explanation:

The sqrt() method returns NaN (not a number) when it's argument is less than zero.

Discussion:
1 comments Page 1 of 1.

Saad said:   1 decade ago
"NaN" stands for "not a number". "Nan" is produced if a floating point operation has some input parameters that cause the operation to produce some undefined result. For example, 0.0 divided by 0.0 is arithmetically undefined. Taking the square root of a negative number is also undefined.

Post your comments here:

Your comments will be displayed after verification.