Question
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");
}
}
}
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");
}
}
}
Answer: Option B
Was this answer helpful ?
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 ?
Submit Solution