9.1.6 Checkerboard V1 Codehs Page

if (frontIsClear()) move(); col++; else break;

: Check if the row index is in the top three (0, 1, 2) or the bottom three (5, 6, 7). If it is, change those elements to 1 . 9.1.6 checkerboard v1 codehs

: Some variations or autograders may require initializing the board with 0s first and then using nested loops to selectively assign to specific indices (e.g., board[i][j] = 1 Autograder Requirements : To pass all tests on , ensure you are using assignment statements if (frontIsClear()) move(); col++; else break; : Check

public class Checkerboard extends ConsoleProgram public void run() // Define the size of the board int numRows = 8; int numCols = 8; // Create the grid Grid board = new Grid(numRows, numCols); // Use a nested loop to traverse every cell for (int row = 0; row < numRows; row++) for (int col = 0; col < numCols; col++) // Check if the sum of row and col is even if ((row + col) % 2 == 0) // Set color (e.g., Black) board.set(row, col, Color.black); else // Set color (e.g., White/Empty) board.set(row, col, Color.white); // Display the board System.out.println(board); Use code with caution. Key Components Explained 1. Nested For Loops A reliable trick is checking if (i + j) % 2 == 0

Use the modulus operator (%) to create the "every other" effect. A reliable trick is checking if (i + j) % 2 == 0 .

Here's the code for the exercise on CodeHS:

Here is the Java code for CodeHS 9.1.6 Checkerboard v1 :