Introduction If you are currently working through the CodeHS Java (or JavaScript) curriculum , particularly the unit on Nested Loops or 2D Arrays , you have likely encountered the infamous exercise: 9.1.7 Checkerboard V2 .

System.out.print("Enter number of rows: "); int rows = input.nextInt(); System.out.print("Enter number of columns: "); int cols = input.nextInt(); for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) if ((i + j) % 2 == 0) System.out.print("@"); else System.out.print("."); System.out.println(); // new line after each row

console.log(line);

var rect = new Rectangle(x, y, SQUARE_SIZE, SQUARE_SIZE); rect.setColor(color); rect.setFilled(true); add(rect);

Instead of two colors, use four colors repeating. Use (row + col) % 4 to choose from an array of colors. Variation C: User Resizable Canvas In the graphics version, recompute square size on window resize. This is rare for CodeHS but possible in advanced sections. Testing Your Solution Before submitting, test these cases manually:

If row % 2 == 1 , start with the opposite color. Equivalent to:

private static final int NUM_ROWS = 8; private static final int NUM_COLS = 8;

@.@.@ .@.@. @.@.@ .@.@. @.@.@ const readline = require('readline'); const rl = readline.createInterface( input: process.stdin, output: process.stdout ); rl.question("Rows: ", (rows) => rl.question("Cols: ", (cols) => rows = parseInt(rows); cols = parseInt(cols); for (let i = 0; i < rows; i++) let line = ""; for (let j = 0; j < cols; j++) if ((i + j) % 2 === 0) line += "X"; else line += "O";