Sail E0 Webinar
Question


What is the output of this program?


class Output {
public static void main(String args[]) {
Double y = new Double(257.57812);
Double i = new Double(257.578123456789);
try {
int x = i.compareTo(y);
System.out.print(x);
}
catch(ClassCastException e) {
System.out.print("Exception");
}
}
}
Options:
A .  0
B .  1
C .  Exception
D .  None of the mentioned
Answer: Option B

i.compareTo() methods two double values, if they are equal then 0 is returned and if 

not equal then 1 is returned, here 257.57812 and 257.578123456789 are not equal 

hence 1 is returned and stored in x.
Output:
$ javac Output.java
$ java Output
1



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers