Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to skip printing the number 3 using the continue statement.
Java
for (int i = 1; i <= 5; i++) { if (i == [1]) { continue; } System.out.println(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using break instead of continue, which stops the whole loop.
Checking for the wrong number to skip.
✗ Incorrect
The continue statement skips the current loop iteration when i equals 3, so 3 is not printed.
2fill in blank
mediumComplete the code to skip all even numbers using continue.
Java
for (int i = 1; i <= 6; i++) { if (i % 2 == [1]) { continue; } System.out.print(i + " "); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0, which skips odd numbers instead.
Forgetting to use continue inside the if.
✗ Incorrect
The condition i % 2 == 0 is true for even numbers, so continue skips printing them.
3fill in blank
hardFix the error in the loop to correctly skip printing negative numbers.
Java
int[] numbers = {2, -3, 5, -1, 4};
for (int num : numbers) {
if (num [1] 0) {
continue;
}
System.out.print(num + " ");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of <, which skips positive numbers.
Using == 0, which skips zero only.
✗ Incorrect
To skip negative numbers, continue when num is less than 0.
4fill in blank
hardFill both blanks to skip numbers divisible by 3 and print others.
Java
for (int i = 1; i <= 10; i++) { if (i [1] 3 == [2]) { continue; } System.out.print(i + " "); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ==, which skips numbers not divisible by 3.
Using > instead of ==, which is incorrect syntax.
✗ Incorrect
The condition i % 3 == 0 is true for numbers divisible by 3, so continue skips them.
5fill in blank
hardFill both blanks to skip numbers less than 5 and print others.
Java
for (int i = 1; i <= 7; i++) { if (i [1] [2]) { continue; } System.out.print(i + " "); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= instead of <, which skips numbers greater or equal to 5.
Using == 5, which skips only number 5.
✗ Incorrect
The condition i < 5 is true for numbers less than 5, so continue skips them.