9.1.7 Checkerboard V2 Answers Guide
The solution to CodeHS 9.1.7: Checkerboard, v2 requires creating an 8x8 grid of alternating 0s and 1s using nested for loops and the modulus operator (%). 1. Initialize the 8x8 Grid
# 2. Use nested loops to replace 0s with 1s in a checkerboard pattern 9.1.7 checkerboard v2 answers
- Black and Gray: Replace
Color.REDwithColor.BLACKandColor.BLACKwithColor.GRAY. - Starting with Black: Change the condition to
(row + col) % 2 != 0for red. - Resizable Canvas: Use
getWidth()andgetHeight()to computeSQUARE_SIZEdynamically:int squareSize = Math.min(getWidth(), getHeight()) / NUM_ROWS; - Method Requirement (v2 specific): The "v2" may demand a helper method:
private void drawSquare(int row, int col, int size) // ... square drawing logicShe pointed to his loop structure on the screen. "Show me your logic." The solution to CodeHS 9
"It’s offset," Leo muttered, burying his face in his hands. "It’s supposed to be offset." Black and Gray: Replace Color
Expanding the Exercise: Beyond the Answers
If you have completed the basic 9.1.7 checkerboard v2 answers, consider challenging yourself with these variations: