var NUM_ROWS = 8; var NUM_COLS = 8; var SQUARE_SIZE = 50; // or calculate based on canvas width/height
Forgetting to add r + c together inside the modulo check. If you only check c % 2 == 0 , you will end up with vertical stripes. If you only check r % 2 == 0 , you will get horizontal stripes.
System.out.print("Enter number of rows: "); int rows = input.nextInt(); System.out.print("Enter number of columns: "); int cols = input.nextInt(); 9.1.7 Checkerboard V2 Codehs
: Create an 8x8 grid (a list of 8 lists, each containing 8 zeros). ): board.append([ Use code with caution. Copied to clipboard Nested Loop Iteration loops to visit every coordinate. Conditional Check : Use the modulus operator to determine which cells to flip. : board[r][c] = Use code with caution. Copied to clipboard Displaying the Result
import java.util.Scanner;
if (row % 2 == 0) // normal parity else // shifted: (col % 2 == 0) gives opposite
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"; var NUM_ROWS = 8; var NUM_COLS = 8;
Some "V2" extensions require non-square patterns. The parity rule still applies, but you might need to offset odd rows. Example: staggered rows like a brick wall.
Row 0: B W B W B W B W Row 1: W B W B W B W B Row 2: B W B W B W B W … System