Question: Consider a class MatrixStuff that has a private instance variable: private int [ ] [ ] mat; Refer to method alter below that occurs in

Consider a class MatrixStuff that has a private instance variable: private int [][] mat;
Refer to method alter below that occurs in the MatrixStuff class. (The lines are numbered for reference.)
Line 1: /** Oparam mat the matrix initialized with integers
Line 2: * Oparam c the column to be removed
Line 3: * Postcondition:
Line 4: *- Column c has been removed.
Line 5: *- The last column is filled with zeros.
Line 6: */
Line 7: public void alter(int [][] mat, int c)
Line 8: {
Line 9: for (int i=0;1 mat.length; 1++)
Line 10: , for (int j=c;j mat 0.length; j++)
Line 11: ,mat[1][j]=mat[1][j+1];
Line 12: //code to insert zeros in rightmost column
Line 13: ,..
Line 14: }
The intent of the method alter is to remove column c. Thus, if the input matrix mat is
\table[[2,6,8,9],[1,5,4,3],[0,7,3,2]]
the method call alter (mat,1) should change mat to
\table[[2,8,9,0],[1,4,3,0],[0,3,2,0]]
The method does not work as intended. Which of the following changes will correct the problem?
I Change line 10 to
for (int j=c;j mat [0].length -1; j++) and make no other changes.
II Change lines 10 and 11 to
for (int j++mat[1][j-1]=mat[1][j]j=j>cj--mat[1][j-1]=mat[i][j]j=c+1;j. length; j++
 Consider a class MatrixStuff that has a private instance variable: private

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!