0
0
Javaprogramming~10 mins

Continue statement in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A3
B2
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using break instead of continue, which stops the whole loop.
Checking for the wrong number to skip.
2fill in blank
medium

Complete 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'
A1
B0
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0, which skips odd numbers instead.
Forgetting to use continue inside the if.
3fill in blank
hard

Fix 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'
A<
B>
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of <, which skips positive numbers.
Using == 0, which skips zero only.
4fill in blank
hard

Fill 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'
A%
B0
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ==, which skips numbers not divisible by 3.
Using > instead of ==, which is incorrect syntax.
5fill in blank
hard

Fill 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'
A<
B5
C>=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= instead of <, which skips numbers greater or equal to 5.
Using == 5, which skips only number 5.