9.1.7 Checkerboard V2 Codehs High Quality
public class CheckerboardV2 extends GraphicsProgram private static final int SIZE = 50; // square side length private static final int ROWS = 8; private static final int COLS = 8;
Inside the nested loop, use the (row + col) % 2 logic to assign 1 to the correct positions using the syntax grid[row][col] = 1 . 9.1.7 Checkerboard V2 Codehs
In earlier versions (like Checkerboard V1), you might have been asked to just fill specific regions (like the top and bottom rows) with In CodeHS, you are typically expected to build an structure
| Test Case | Expected Behavior | |-----------|------------------| | 1x1 board | Single square | | 1x5 board | Horizontal alternating pattern | | 5x1 board | Vertical alternating pattern | | 2x2 board | Top-left = dark, top-right = light, bottom-left = light, bottom-right = dark | | 10x10 board | Perfect checkerboard, no line breaks inside | outer loop iterates through the row indices (
First, create a variable to hold your grid. You will start with an empty list and then append rows to it. In CodeHS, you are typically expected to build an structure. 2. Create the Nested Loops You need two loops: one for the rows and one for the columns. outer loop iterates through the row indices ( inner loop iterates through the column indices ( 3. Apply the Alternating Pattern Inside the nested loop, check the sum of the current . Use the modulus operator to check for even or odd values. if (row + col) % 2 == 0 If true, set the cell to If false, set the cell to 4. Print the Result
If the sum of the row index ( i ) and column index ( j ) is even, the value should be 1 . If it is odd, the value should be 0 (or vice versa).