Boolean Expressions

AP Computer Science A· difficulty 2/5

int x = 3;
int y = 3;
if (x == y) {
  System.out.println("equal");
} else {
  System.out.println("not equal");
}

What is printed?

  • A

    not equal

  • B

    equal

    check_circle
  • C

    compile error

  • D

    true

Explanation

== is the equality comparison operator. x and y both equal 3, so the condition is true and "equal" is printed.

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

Related questions