Complete the code to print numbers from 1 to 5 using a while loop.
int i = 1; while (i [1] 5) { System.out.println(i); i++; }
The condition i <= 5 makes the loop run while i is less than or equal to 5, printing 1 to 5.
Complete the code to keep asking the user for input until they enter 0.
Scanner scanner = new Scanner(System.in); int num; do { System.out.print("Enter a number: "); num = scanner.nextInt(); } while (num [1] 0);
The loop continues while the number is not equal to 0, so it stops when the user enters 0.
Fix the error in the while loop condition to avoid an infinite loop.
int count = 0; while (count [1] 5) { System.out.println(count); count++; }
The condition count < 5 makes the loop run 5 times, printing 0 to 4.
Fill both blanks to create a while loop that prints even numbers less than 10.
int num = 0; while (num [1] 10) { if (num % 2 == 0) { System.out.println(num); } num[2]; }
The loop runs while num is less than 10, and num is increased by 1 each time to avoid infinite loop.
Fill all three blanks to create a while loop that sums numbers from 1 to 5.
int sum = 0; int i = 1; while (i [1] 5) { sum [2] i; i[3]; } System.out.println(sum);
The loop runs while i is less than or equal to 5, adds i to sum, and increments i by 1 each time.