Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the counter variable.
Java
int count = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting the counter at 1 instead of 0.
Using a negative number as the starting value.
✗ Incorrect
The counter variable should start at 0 to count from the beginning.
2fill in blank
mediumComplete the code to write the while loop condition to run 5 times.
Java
while (count [1] 5) { System.out.println(count); count++; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than instead of less than.
Using equality which runs only once.
✗ Incorrect
The loop should run while count is less than 5 to execute 5 times (0 to 4).
3fill in blank
hardFix the error in the loop increment statement.
Java
while (count < 5) { System.out.println(count); count[1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' without assignment.
Using '--' which decreases the counter.
✗ Incorrect
The increment operator '++' increases count by 1 each loop.
4fill in blank
hardFill both blanks to create a loop that counts down from 5 to 1.
Java
int count = [1]; while (count [2] 0) { System.out.println(count); count--; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting count at 0 instead of 5.
Using '<' which would cause an infinite loop.
✗ Incorrect
Start count at 5 and loop while count is greater than 0 to count down.
5fill in blank
hardFill all three blanks to create a loop that prints even numbers from 2 to 10.
Java
int count = [1]; while (count [2] 10) { System.out.println(count); count [3] 2; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 instead of 2.
Using '<' which excludes 10.
Using '+' without assignment.
✗ Incorrect
Start at 2, loop while count is less or equal to 10, and add 2 each time to print even numbers.