-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion41.java
More file actions
38 lines (34 loc) · 1 KB
/
question41.java
File metadata and controls
38 lines (34 loc) · 1 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
public class question41 {
public static void main(String[] args) {
int[][] matrix = {
{1, 2, 3},
{4, 0, 6},
{7, 8, 9}
};
int rows = matrix.length;
int cols = matrix[0].length;
boolean[] row = new boolean[rows];
boolean[] col = new boolean[cols];
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(matrix[i][j] == 0){
row[1] = true;
col[1] = true;
}
}
}
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(row[i] || col[j]){
matrix[i][j] = 0;
}
}
}
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}
}