if Statements and Control Flow

AP Computer Science A· difficulty 3/5

int x = 5;
int y = 10;
if (x > 0) {
  if (y > x) {
    System.out.println("A");
  } else {
    System.out.println("B");
  }
} else {
  System.out.println("C");
}

What is printed?

  • A

    A

    check_circle
  • B

    B

  • C

    C

  • D

    A B

Explanation

x > 0 is true, so we enter the outer if. y > x is 10 > 5, true, so "A" is printed.

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

Related questions