This repository was archived by the owner on Dec 7, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZeroMatrix.java
More file actions
Latest commit
53 lines (46 loc) · 1.29 KB
/
Copy pathZeroMatrix.java
File metadata and controls
53 lines (46 loc) · 1.29 KB
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
46
47
48
49
50
51
52
53
packagecom.ematrix;
importjava.util.Arrays;
publicclassZeroMatrix {
publicvoidtransForm(int[][] S){
intn=S.length;
System.out.print(n);
boolean[] rows=newboolean[S.length];
boolean[] columns=newboolean[S[0].length];
Arrays.fill(rows,false);
Arrays.fill(columns,false);
for(inti=0;i<n;i++){
for(intj=0;j<S[i].length;j++){
if(S[i][j]==0){
rows[i] =true;
columns[j]=true;
}
}
}
for(inti=0;i<n;i++){
for(intj=0;j<S[i].length;j++){
if(rows[i]){
S[i][j]=0;
}
if( columns[j]){
S[i][j]=0;
}
}
}
}
publicstaticvoidmain(String[] args) {
int[][] a = {
{0, 2, 3, 4,5},
{5, 6, 7, 0,4},
{9,10,11,12,6},
{13,7,15,16,7}
};
ZeroMatrixzeroMatrix =newZeroMatrix();
zeroMatrix.transForm(a);
for (inti = 0; i < a.length; ++i) {
for(intj = 0; j < a[i].length; ++j) {
System.out.print(a[i][j]+"\t");
}
System.out.print("\n");
}
}
}