if-else Statements

AP Computer Science A· difficulty 3/5

int x = 10;
String label = "none";
if (x > 0) {
  label = "positive";
}
if (x > 5) {
  label = "big";
}
System.out.println(label);

What is printed?

  • A

    none

  • B

    positive big

  • C

    big

    check_circle
  • D

    positive

Explanation

These are two SEPARATE if statements (no else). With x = 10, both run. label is set to "positive" then overwritten to "big". Final value printed is "big".

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

Related questions