Compound Boolean Expressions

AP Computer Science A· difficulty 3/5

boolean b;
if (x == y) b = false;
else b = true;

Which one-liner is equivalent?

  • A

    boolean b = x = y;

  • B

    boolean b = x != y;

    check_circle
  • C

    boolean b = !x == y;

  • D

    boolean b = x == y;

Explanation

The result is the negation of equality, which is exactly x != y.

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

Related questions