Home » JAVA Programming » Methods » Question
  1. What is the output of this program?
    public class Result
    {
    public static void main(String args[])
    {
    Double num0 = new Double(260.0062);
    Double num1 = new Double(260.0062123456);
    try
    {
    int p = num1.compareTo(num0);
    System.out.print(p);
    }
    catch(ClassCastException e)
    {
    System.out.print("Exception");
    }
    }
    }
    1. Exception
    2. 0
    3. 1
    4. -1
    5. None of these
Correct Option: C

num1.compareTo() methods two double values, if they are equal then 0 is returned and if not equal then 1 is returned, here 260.0062 and 260.0062123456 are not equal hence 1 is returned and stored in p.



Your comments will be displayed only after manual approval.