for Loops

AP Computer Science A· difficulty 2/5

int i = 5;
while (i > 0) {
  System.out.print(i);
  i--;
}

What is printed?

  • A

    12345

  • B

    54321

    check_circle
  • C

    5432

  • D

    01234

Explanation

The while prints i then decrements, while i > 0: prints 5, 4, 3, 2, 1. After i becomes 0, condition is false. Output is "54321".

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

Related questions