Complete the code to create a while loop that prints numbers from 1 to 3.
int i = 1; while ([1]) { System.out.println(i); i++; }
The condition i <= 3 ensures the loop runs while i is 1, 2, or 3.
Complete the code to create a do-while loop that prints numbers from 1 to 3.
int i = 1; do { System.out.println(i); i++; } while ([1]);
The condition i <= 3 makes the do-while loop run while i is 1, 2, or 3.
Fix the error in the while loop condition to avoid an infinite loop.
int count = 5; while ([1]) { System.out.println(count); count--; }
The condition count >= 0 ensures the loop stops when count becomes -1, preventing infinite looping.
Fill both blanks to create a while loop that prints even numbers from 2 to 6.
int num = 2; while ([1]) { System.out.println(num); num [2] 2; }
The condition num <= 6 keeps the loop running until 6. The operator += adds 2 each time to get even numbers.
Fill all three blanks to create a do-while loop that prints numbers from 1 to 5.
int i = [1]; do { System.out.println(i); i [2] 1; } while (i [3] 5);
Start i at 1, increase it by 1 each time with +=, and continue while i <= 5.