Complete the code to print numbers from 1 to 3 using a for loop.
for (int i = 1; i [1] 4; i++) { System.out.println(i); }
The loop runs while i is less than 4, so it prints 1, 2, and 3.
Complete the code to print a 3x3 grid of stars using nested for loops.
for (int i = 1; i <= 3; i++) { for (int j = 1; j [1] 4; j++) { System.out.print("*"); } System.out.println(); }
The inner loop runs while j is less than 4, printing 3 stars each row.
Fix the error in the nested loop to print numbers 1 to 3 in each row.
for (int i = 1; i <= 3; i++) { for (int j = 1; j [1] 3; j++) { System.out.print(j + " "); } System.out.println(); }
The inner loop should run while j is less than or equal to 3 to print numbers 1, 2, and 3.
Fill both blanks to create a nested loop that prints a 4x4 grid of numbers.
for (int i = 1; i [1] 5; i++) { for (int j = 1; j [2] 5; j++) { System.out.print(j + " "); } System.out.println(); }
Both loops run while the variable is less than 5, printing numbers 1 to 4 in each row and column.
Fill all three blanks to create a nested loop that prints a triangle of stars.
for (int i = 1; i [1] 5; i++) { for (int j = 1; j [2] i; j[3]) { System.out.print("*"); } System.out.println(); }
The outer loop runs from 1 to 5 inclusive. The inner loop runs from 1 up to i inclusive, printing stars. The j variable increments by 1 each time.