while Loops

AP Computer Science A· difficulty 3/5

int x = 10;
do {
  System.out.println(x);
  x++;
} while (x < 5);

What is printed?

  • A

    nothing

  • B

    5

  • C

    10 11 12 13 14

  • D

    10

    check_circle

Explanation

do-while runs the body at least once before checking the condition. It prints 10, increments x to 11, then checks 11 < 5 which is false, so the loop exits.

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

Related questions