Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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++
image text in transcribed

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

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions

Question

design a simple disciplinary and grievance procedure.

Answered: 1 week ago