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

Discussion :: Java.lang Class

  1. What will be the output of the program?

    System.out.println(Math.sqrt(-4D));

  2. A.
    -2
    B.
    NaN
    C.
    Compile Error
    D.
    Runtime Exception

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    It is not possible in regular mathematics to get a value for the square-root of a negative number therefore a NaN will be returned because the code is valid.


Be The First To Comment