Java Source Code
System.out Console
2-D Array Memory Grid — Swipe or use Next ▶ to trace indices
Active cell
grid[r][c] Processed Target match Out-of-boundsReady. Step through the code with Next ▶
2-D Arrays & Nested Loops — Core Rules
| Expression | Meaning in Java | Common Pitfall |
|---|---|---|
grid.length | Number of rows in the 2-D array | Confusing grid.length with number of columns |
grid[r].length | Number of columns in row r | Hardcoding column count fails on jagged arrays |
grid[r][c] | Row index r first, column index c second | Swapping [c][r] when traversing column-by-column |
continue vs break | continue skips current iteration; break exits the innermost loop only | Expecting break in inner loop to exit outer loop too |
Classroom Teaching Guide
1. Array of arrays: Remind students that Java stores a 2-D array as a 1-D array of row references—which is why
2. Loop speed difference: Notice how the outer loop variable (
3. Controls: Use ← / → keys on desktop or swipe left/right on mobile phones.
grid[r].length can vary per row.2. Loop speed difference: Notice how the outer loop variable (
r) stays fixed while the inner loop variable (c) cycles through all columns.3. Controls: Use ← / → keys on desktop or swipe left/right on mobile phones.