8.1.5 Manipulating 2d Arrays __link__ — Codehs

For example:

In CodeHS 8.1.5, "Manipulating 2D Arrays," the objective is typically to modify specific elements or rows within a 2D array (a list of lists) using nested loops or direct indexing.

// Example: Replacing all -1s with 0 if (arr[r][c] == -1) arr[r][c] = 0; Use code with caution. 3. Cumulative Operations (Summing)

If you are still struggling with a specific scenario within the 8.1.5 challenge, please share the code snippet or the problem description. I can help with: specific errors in your code. Explaining why a certain loop structure isn't working. Providing a hint for the logic required for the 8.1.5 task. Codehs 8.1.5 Manipulating 2d Arrays

This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later.

// Example: Creating a 3x3 grid of integers int[][] grid = new int[3][3]; Use code with caution.

function getEvens(matrix) let result = []; for (let i = 0; i < matrix.length; i++) let evenRow = []; for (let j = 0; j < matrix[i].length; j++) if (matrix[i][j] % 2 === 0) evenRow.push(matrix[i][j]); For example: In CodeHS 8

console.log(array); // output: [[1, 3], [4, 6], [7, 9]]

What a 2D array is

// Syntax for declaring a 2D array int[][] matrix = new int[rows][columns]; Use code with caution. Traversal Strategies Cumulative Operations (Summing) If you are still struggling

// Task 2: Write a function that returns a new 2D array with only the even numbers function getEvens(matrix) // Your code here

Think of a 2D array as a table, a matrix, or, as the course describes it, "a grid, table, or list of lists". In Java, a 2D array is actually an "array of arrays." The row index refers to a specific one-dimensional array, and the column index picks an element within that array.

Java stores 2D arrays row by row. The first index always represents the row, and the second index represents the column.