Question: Write a method named zeroRowCol that accepts a 2 - D array of integers as a parameter and modifies its contents by setting any element

Write a method named zeroRowCol that accepts a 2-D array of integers as a parameter and modifies its contents by setting any element value to 0 if there is a 0 in that row and/or in that column. For example, if a variable called matrix stores the following values:
int[][] matrix ={{0,1,4,0},{3,2,6,4},{-1,3,1,8},{15,7,2,0},{9,4,5,6}};
Then the call of zeroRowCol(matrix) should modify its state to be the following:
{{0,0,0,0},{0,2,6,0},{0,3,1,0},{0,0,0,0},{0,4,5,0}}
Your code should work for an array of any size, even one with 0 rows or columns.

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 Programming Questions!