Nested Iteration MCQ Practice

Question 1 of 10

A mural club stamps stars in a small grid. What text does this Java code display?

for (int row = 1; row <= 3; row++) {
    for (int col = 1; col <= 2; col++) {
        System.out.print("*");
    }
}
  1. A. ***
  2. B. ******
  3. C. **
  4. D. ************

Question 2 of 10

A ticket window reprints inner numbers on every outer pass. What text does this Java code display?

int outer = 1;
while (outer <= 2) {
    int inner = 1;
    while (inner <= 3) {
        System.out.print(inner);
        inner++;
    }
    outer++;
}
  1. A. 123123
  2. B. 123
  3. C. 112233
  4. D. 123456

Question 3 of 10

A greenhouse prints one row of tags, then moves to a new line. What text does this Java code display?

for (int r = 0; r < 2; r++) {
    for (int c = 0; c < 3; c++) {
        System.out.print("#");
    }
    System.out.println();
}
  1. A. ######
  2. B. # # # # # #
  3. C. ### ###
  4. D. ### ### ###

Question 4 of 10

A choir prints a growing count on one line. What text does this Java code display?

for (int r = 1; r <= 4; r++) {
    for (int c = 1; c <= r; c++) {
        System.out.print(c);
    }
}
  1. A. 1234123412341234
  2. B. 1234
  3. C. 123123123123
  4. D. 1121231234

Question 5 of 10

A stamp desk counts nested passes. What text does this Java code display?

int stamps = 0;
for (int a = 0; a < 4; a++) {
    for (int b = 0; b <= 3; b++) {
        stamps++;
    }
}
System.out.print(stamps);
  1. A. 16
  2. B. 12
  3. C. 9
  4. D. 7

Question 6 of 10

A robotics squad prints the outer index on each inner pass. What text does this Java code display?

for (int p = 1; p <= 3; p++) {
    for (int q = p; q <= 3; q++) {
        System.out.print(p);
    }
}
  1. A. 123123123
  2. B. 122333
  3. C. 111223
  4. D. 123

Question 7 of 10

A bakery adds the outer batch size twice on every tray. What text does this Java code display?

int total = 0;
for (int i = 1; i <= 4; i++) {
    int j = 0;
    while (j < 2) {
        total += i;
        j++;
    }
}
System.out.print(total);
  1. A. 10
  2. B. 8
  3. C. 16
  4. D. 20

Question 8 of 10

A fence printer may skip inner marks when the inner bound starts too high. What text does this Java code display?

for (int row = 1; row <= 3; row++) {
    for (int col = 1; col < row; col++) {
        System.out.print("*");
    }
    System.out.print("|");
}
  1. A. ***|||
  2. B. |*|**|
  3. C. *|**|***|
  4. D. |*|*|*|

Question 9 of 10

A lab counter resets the inner index on every outer pass. What text does this Java code display?

int a = 0;
int hits = 0;
while (a < 3) {
    int b = 0;
    while (b <= a) {
        hits++;
        b++;
    }
    a++;
}
System.out.print(hits);
  1. A. 6
  2. B. 3
  3. C. 9
  4. D. 4

Question 10 of 10

A scoreboard prints inner digits, then a marker, after each outer value. What text does this Java code display?

for (int n = 2; n <= 4; n++) {
    for (int k = 1; k < n; k++) {
        System.out.print(k);
    }
    System.out.print("x");
}
  1. A. 12x123x1234x
  2. B. x1x12x123
  3. C. 1x12x123x
  4. D. 123x123x123x