String Methods

AP Computer Science A· difficulty 4/5

String a = "dog";
String b = "cat";
System.out.println(a.compareTo(b) > 0);

What is printed?

  • A

    true

    check_circle
  • B

    false

  • C

    0

  • D

    1

Explanation

"dog" comes after "cat" lexicographically, so a.compareTo(b) returns a positive integer, which is greater than 0.

Want 10 more like this — adaptive to your weak spots?

Related questions