-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog21.java
61 lines (60 loc) · 1.1 KB
/
prog21.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 A
{
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
int e=0, o=0;
System.out.print("Enter the number of rows : ");
int r = sc.nextInt();
System.out.print("Enter the number of cols : ");
int c = sc.nextInt();
int A[][] = new int [r][c];
System.out.println("Enter "+r+"x"+c+" array :");
for (int i=0;i<r;i++)
{
for (int j=0;j<c;j++)
{
A[i][j]=sc.nextInt();
if (A[i][j]%2==0)
{
e++;
}
else
{
o++;
}
}
}
int even[] = new int [e];
int odd[] = new int [o];
e=0;
o=0;
for (int i=0;i<r;i++)
{
for (int j=0;j<c;j++)
{
if(A[i][j]%2==0)
{
even[e++]=A[i][j];
}
else
{
odd[o++]=A[i][j];
}
}
}
System.out.print("Even : ");
for (int i =0;i<even.length;i++)
{
System.out.print(even[i]+" ");
}
System.out.println();
System.out.print("Even : ");
for (int i =0;i<odd.length;i++)
{
System.out.print(odd[i]+" ");
}
System.out.println();
}
}