Skip to Main Content

9.1.7 Checkerboard V2 Codehs -

public void run() double sqWidth = (double) getWidth() / NUM_COLS; double sqHeight = (double) getHeight() / NUM_ROWS; for (int row = 0; row < NUM_ROWS; row++) for (int col = 0; col < NUM_COLS; col++) double x = col * sqWidth; double y = row * sqHeight; GRect square = new GRect(x, y, sqWidth, sqHeight); square.setFilled(true); if ((row + col) % 2 == 0) square.setFillColor(Color.BLACK); else square.setFillColor(Color.RED); add(square);

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 9.1.7 Checkerboard V2 Codehs

@.@.@ .@.@. @.@.@ .@.@. @.@.@ 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"; public void run() double sqWidth = (double) getWidth()

console.log(line);