The method changeNegs below should replace every occurrence of a negative integer in its matrix parameter with 0.
/** @param mat the matrix
* Precondition: mat is initialized with integers.
* Postcondition: All negative values in mat replaced with 0.
*/
public static void changeNegs(int[][] mat)
{
/* code */
}
Which is correct replacement for /* code */?
I
for (int r = 0; r < mat.Length; r++)
for (int c = 0; c < mat[r].Length; c++
if (mat[r][c] < 0)
mat[r][c] = 0;
II
for (int c = 0; c < mat[0].Length; c++)
for (int r = 0; r < mat.Length; r++)
if (mat[r][c] < 0)
mat[r][c] = 0;
III
foreach (int[] row in mat)
for (int element : row)
if (element < 0)
element = 0;
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III