-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.java
65 lines (59 loc) · 1.09 KB
/
matrix.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
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.Scanner;
class matrix
{
public static void main(String args[])
{
int a[][] = new int[6][6];
Scanner sc = new Scanner(System.in);
System.out.println("Enter Matrix elements (only 0 or 1) row wise: ");
for(int i=0;i<6;i++)
{
for(int j=0;j<6;j++)
a[i][j]=sc.nextInt();
}
System.out.println("The Matrix: ");
for(int i=0;i<6;i++)
{
for(int j=0;j<6;j++)
System.out.print(" "+a[i][j]+" ");
System.out.println(" ");
}
matrix.oddCheck(a);
}
static void oddCheck(int b[][])
{
int temp,i,j;
System.out.println("Rows having odd number of 1's: ");
for(i=0;i<6;i++)
{
temp=0;
for(j=0;j<6;j++)
{
if(b[i][j] == 1)
temp++;
}
if(temp%2!=0)
{
for(j=0;j<6;j++)
System.out.print(" "+b[i][j]+" ");
System.out.println(" ");
}
}
System.out.println("Columns having odd number of 1's: ");
for(i=0;i<6;i++)
{
temp=0;
for(j=0;j<6;j++)
{
if(b[j][i] == 1)
temp++;
}
if(temp%2!=0)
{
for(j=0;j<6;j++)
System.out.println(" "+b[j][i]+" ");
System.out.println("_____");
}
}
}
}