Nested Loops in Java

Nested Loops in Java

Nested Loops with Multiplication Table, Nested Loops with Condition, Nested Loops with Break, Nested Loops with Continue, Multiplication Table with Nested Loops, Nested Loops with Different Ranges, Nested Loops with Decrement, Pyramid Pattern, Triangular Number Pattern, Complex Nested Loops

1 / 10

What will the following code output?

for (int i = 1; i <= 2; i++) { for (int j = 1; j <= 3; j++) { System.out.print(i * j + " "); } System.out.println(); }

2 / 10

What will the following code output?

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (i == j) { System.out.print(i + " "); } } }

3 / 10

What will the following code output?

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (j == 2) break; System.out.print(i + "" + j + " "); } }

4 / 10

What will the following code output?

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (j == 2) continue; System.out.print(i + "" + j + " "); } }

5 / 10

What will the following code output?

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { System.out.print(i * j + " "); } System.out.println(); }

6 / 10

What will the following code output?

for (int i = 1; i <= 3; i++) { for (int j = i; j <= 3; j++) { System.out.print(j + " "); } }

7 / 10

What will the following code output?

for (int i = 3; i >= 1; i–) {
for (int j = i; j >= 1; j–) {
System.out.print(j + ” “);
}
System.out.println();
}

8 / 10

What will the following code output?

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= i; j++) { System.out.print("* "); } System.out.println(); }

9 / 10

What will the following code output?

for (int i = 1; i <= 4; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); }

10 / 10

What will the following code output?

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= i; j++) { for (int k = 1; k <= j; k++) { System.out.print(k + " "); } System.out.println(); } System.out.println(); }

Your score is

Scroll to Top