Write two methods in java. The first called copyColumns(int [][] a, int index) returns a copy of column index of array a
Posted: Tue Jul 12, 2022 8:15 am
Write two methods in java. The first called copyColumns(int[][] a, int index) returns a copy of column index of array a. If ais null or if the value a[index] does not exist (index is out ofbounds) return null.
Given the two dimensional array
int [][] td = { {1, 2, 3}, {3, 4, 5}, {6, 7, 8} };
then
copyColumns(td, 0) returns the array {1, 3, 6} copyColumns(td,2) returns {3, 5, 8} copyColumns(td, -20) returns nullcopyCoumns(tf, 5) returns null
The second is called copyToRows(int [] a), returns a twodimensional array with the number of rows being the size of array aand the number of columns of row i being the value in a. If thevalue is zero or less, create a row of size 0. For example, giventhe array
int [] a = { 4, -1, 3, 10 };
copyToRows(a) returns the two dimensional array 4 4 4 4
3 3 310 10 10 10 10 10 10 10 10 10
That is, row 0 has four colums (with the value 4 in eachcolumn), row 1 has two columns, row 2 has 3 columns, and row 3 hasten columns. The number of columns in row i is the value ofa.
Given the two dimensional array
int [][] td = { {1, 2, 3}, {3, 4, 5}, {6, 7, 8} };
then
copyColumns(td, 0) returns the array {1, 3, 6} copyColumns(td,2) returns {3, 5, 8} copyColumns(td, -20) returns nullcopyCoumns(tf, 5) returns null
The second is called copyToRows(int [] a), returns a twodimensional array with the number of rows being the size of array aand the number of columns of row i being the value in a. If thevalue is zero or less, create a row of size 0. For example, giventhe array
int [] a = { 4, -1, 3, 10 };
copyToRows(a) returns the two dimensional array 4 4 4 4
3 3 310 10 10 10 10 10 10 10 10 10
That is, row 0 has four colums (with the value 4 in eachcolumn), row 1 has two columns, row 2 has 3 columns, and row 3 hasten columns. The number of columns in row i is the value ofa.