In the typical CodeHS progression (specifically in the AP Computer Science A or Introduction to Java tracks), is a coding exercise found in the "2D Arrays" module. By this point, you already know how to declare ( int[][] matrix = new int[3][3]; ) and traverse a 2D array using nested loops. However, 8.1.5 asks you to go a step further: modify the array in place based on specific conditions.
for (int r = 0; r < grid.length; r++) for (int c = 0; c < grid[r].length; c++) // Manipulation logic goes here Codehs 8.1.5 Manipulating 2d Arrays
A: While not the standard prompt, if asked to reverse each row, use a two-pointer swap inside each row: swap arr[row][left] with arr[row][right] until pointers meet. In the typical CodeHS progression (specifically in the
Change an element based on the value of its neighbor (e.g., if the element above is even, set current to zero). for (int r = 0; r < grid
: Review the official documentation on declaration and initialization. YouTube: AP CSA Unit 8 Intro : A great visual guide on how these grids look in memory. Runestone Academy: 2D Arrays : Interactive practice for setting values in a grid. Are you having trouble with a specific error message or one of the test cases 8.1 2D Arrays - CodeHS
8.9.2. Picture Lab A4: 2D Arrays in Java - Runestone Academy
// Double every element in the second row (index 1) int targetRow = 1; for (int col = 0; col < arr[targetRow].length; col++) arr[targetRow][col] *= 2;