Home / Java Programming / Java.lang Class :: Discussion

Discussion :: Java.lang Class

  1. 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));     } } 

  2. A.
    3.0
    B.
    -3.0
    C.
    NaN
    D.
    Compilation fails.

    View Answer

    Workspace

    Answer : Option C

    Explanation :

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


Be The First To Comment