The program is run with java -ea Case70 - what will be the output?
public class Case70
{
public static void main(String[] args)
{
assert "A".equalsIgnoreCase("a");
System.out.println("A".compareTo("a"));
}
}
Answer: B
equalsIgnoreCase reports the two strings as equal, so the assertion passes. compareTo is case sensitive and returns the difference of the first differing characters, and A is 65 while a is 97, so the result is -32. The two methods disagree deliberately.
Please log in or register to report this question.