else if Statements

AP Computer Science A· difficulty 3/5

int score = 95;
if (score >= 70) {
  System.out.println("C");
}
if (score >= 80) {
  System.out.println("B");
}
if (score >= 90) {
  System.out.println("A");
}

What is printed (each on its own line)?

  • A

    C, B, A on three lines

    check_circle
  • B

    A only

  • C

    C only

  • D

    A, B, C on three lines

Explanation

These are three separate if statements (not else if). All three conditions are true for score 95, so "C", "B", and "A" all print in that order.

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

Related questions