Iteration constructs in Java

Iteration constructs in Java

Basic for-loop, Nested Loops, Infinite Loop, Enhanced for-loop, Break Statement, Continue Statement, Do-While Loop, Nested Loops with Break, For-loop with Multiple Variables, Infinite While Loop

1 / 10

What will the following code output?

for (int i = 0; i < 5; i++) { System.out.print(i + " "); }

2 / 10

What will the following code output?

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

3 / 10

Which of the following results in an infinite loop?

4 / 10

What will the following code output?

int[] numbers = {1, 2, 3, 4, 5};
for (int num : numbers) {
System.out.print(num + ” “);
}

5 / 10

What will the following code output?

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

6 / 10

What will the following code output?

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

7 / 10

What will the following code output?

int i = 1;
do {
System.out.print(i + ” “);
i++;
} while (i <= 3);

8 / 10

What will the following code output?

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

9 / 10

What will the following code output?

for (int i = 0, j = 5; i < j; i++, j--) { System.out.print(i + "" + j + " "); }

10 / 10

Which of the following will result in an infinite loop?

Your score is

Scroll to Top