-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetMatrixZeros.java
More file actions
45 lines (35 loc) · 955 Bytes
/
SetMatrixZeros.java
File metadata and controls
45 lines (35 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package codingInterview;
public class SetMatrixZeros {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] mat = new int[5][4];
int m = 4, n = 4;
int value = -1;
initiateMat(mat, m, n, value);
mat[1][2] = 0;
mat[3][3] = 0;
printMat(mat, m, n);
setZero(mat, m, n);
printMat(mat, m, n);
}
private static void initiateMat(int[][] mat, int m, int n, int value) {
// TODO Auto-generated method stub
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
mat[i][j] = value;
}
}
}
private static void setZero(int[][] mat, int m, int n) {
// TODO Auto-generated method stub
}
private static void printMat(int[][] mat, int m, int n) {
// TODO Auto-generated method stub
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(j == n - 1 ? mat[i][j] + "\n" : mat[i][j] + " ");
}
}
System.out.println("------------------");
}
}