Question: The last element in each array in a 2D array is incorrect. Its your job to fix each array so that the value 0 is

The last element in each array in a 2D array is incorrect. Its your job to fix each array so that the value 0 is changed to include the correct value.

In the first array, the final value should be the length of the first array.

In the second array, the final value should be the sum of the first value, and the second to last value in the array.

In the third array, the final value should be the length of the 2D array.

Create a method called fixArray(int[][] array, int row, int col, int value) that sets the [row][column] to the correct value. Then, call the fixArray method three times - once for each value change that you are supposed to make.

When inputting values to fixArray, you will have to hard code the row value, but the column value and the new value should be set using the array accessor methods. For example, if we wanted to set the value of the first index in the first array to the length of the 2D array, we would write:

fixArray(array, 0, 0, array.length)

-----------------------------------

public class ArrayPractice { public static void main(String[] args) { int[][] array = {{5, 4, 2, 1, 0}, {523, 63, 2342, 586, 1, 6534, 0}, {10, 9, 2, 0}}; //Call the fixArray method three times on this array: print(array); } //Create a method to add the correct value to the array at the correct col, row public static void fixArray(int[][] arr, int row, int col, int value) { } //Do not make alterations to this method! public static void print(int[][] array) { for(int[] row: array) { for(int num: row) { System.out.print(num + " "); } System.out.println(); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!