Write two methods in java. The first called copyColumns(int [][] a, int index) returns a copy of column index of array a

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write two methods in java. The first called copyColumns(int [][] a, int index) returns a copy of column index of array a

Post by answerhappygod »

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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply