-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpac11.java
48 lines (47 loc) · 1.4 KB
/
pac11.java
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
class pac11 {
public static int[][] create_arr() {
int[][] arr = new int[6][6];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
arr[i][j] = (int) ((Math.random() * 5) % 2);
}
}
System.out.print("\nMatrix Values \n");
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
return arr;
}
public static void main(String[] args) {
int arr[][];
int i, j, count;
arr = create_arr();
System.out.println("\nRows Having ODD no of 1s");
for (i = 0; i < 6; i++) {
count = 0;
for (j = 0; j < 6; j++) {
if (arr[i][j] == 1) {
count++;
}
}
if (count % 2 != 0) {
System.out.println("Row - " + (i + 1) + " has ODD no of 1s");
}
}
System.out.println("\nColumns Having ODD no of 1s");
for (i = 0; i < 6; i++) {
count = 0;
for (j = 0; j < 6; j++) {
if (arr[j][i] == 1) {
count++;
}
}
if (count % 2 != 0) {
System.out.println("Column - " + (i + 1) + " has ODD no of 1s");
}
}
}
}