Nested Iteration

AP Computer Science A· difficulty 3/5

int count = 0;
for (int i = 0; i < 3; i++) {
  for (int j = 0; j < 4; j++) {
    count++;
  }
}
System.out.println(count);

What is printed?

  • A

    7

  • B

    12

    check_circle
  • C

    16

  • D

    9

Explanation

Outer loop runs 3 times, inner loop runs 4 times each. Total iterations = 3 * 4 = 12.

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

Related questions

AP Computer Science A · Nested Iteration Practice Question | Acemy