Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

8.1.5 Manipulating 2D Arrays Please complete the code in Java public class ArrayPractice { public static void main(String[] args) { int[][] array = {{5, 4,

8.1.5 Manipulating 2D Arrays

Please complete the code in Java

image text in transcribed

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(); } } }

8.1.5: Manipulating 2D Arrays Save Submit + Continue RUN CODE | TEST CASES ASSIGNMENT DOCS | GRADE MORE 5 points Status: Not Submitted The last element in each array in a 2D array is incorrect. It's your job to fix each array so that the value O 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. 1 public class ArrayPractice 2- { 3 public static void main(String[] args) 4 - { 5 int[][] array {{5, 4, 2, 1, 0}, {523, 63, 2342, 586, 1, 6534, 0}, {10, 9, 2, 0}}; 6 //Call the fixArray method three times on this array: 7 8 9 10 print(array); 11 } 12 13 //Create a method to add the correct value to the array at the correct col, row 14 public static void fixArray(int[] [] arr, int row, int col, int value) 15 { 16 17 } 18 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: 19 20 21 fixArray(array, 0, 0, array.Length) 22 23 24 25- 26 27 - 28 29 30 31 32 33 } //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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions