Boolean Expressions

AP Computer Science A· difficulty 2/5

int a = 5;
int b = 5;
if (a != b) {
  System.out.println("X");
} else {
  System.out.println("Y");
}

What is printed?

  • A

    Y

    check_circle
  • B

    X

  • C

    true

  • D

    false

Explanation

a and b are equal, so a != b is false, and the else branch prints "Y".

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

Related questions