The "9.1.6 Checkerboard v1" exercise in CodeHS is a classic challenge designed to test your mastery of nested loops and 2D arrays (or grids). Creating a checkerboard pattern requires a logical approach to alternating colors based on row and column indices.
(i + j) % 2 == 0 checks if the sum of the row and column indices is evenOff-by-one errors: Ensure your loops run while row < numRows, not <=, or you’ll hit an IndexOutOfBounds error. 9.1.6 checkerboard v1 codehs
Setting the Color:
// 4. Add the rectangle to the Grid to visualize it grid.add(rect, row, col); // 1. Create a new Rectangle object Rectangle rect = new Rectangle();Alternatively, you can think of it as: if the row is even, start with color A; if the row is odd, start with color B. The Code Implementation (Java/CodeHS Style) The "9