String Comparison
A program compares two distinct String objects using the compareTo method to determine lexicographical order.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
String a = "Apple";
String b = "Banana";
int val = a.compareTo(b);
System.out.println(val < 0);
}
}
A
-1
B
0
C
true
D
false
Question Leaderboard
Not enough data yet to show leaderboard.
