-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathOddEven.java
More file actions
30 lines (26 loc) · 1017 Bytes
/
OddEven.java
File metadata and controls
30 lines (26 loc) · 1017 Bytes
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
public class OddEven
{
public static void main(String[] args) {
int rows, cols, countOdd = 0, countEven = 0;
//Initialize matrix a
int a[][] = {
{4, 1, 3},
{3, 5, 7},
{8, 2, 6}
};
//Calculates number of rows and columns present in given matrix
rows = a.length;
cols = a[0].length;
//Counts the number of even elements and odd elements
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(a[i][j] % 2 == 0)
countEven++;
else
countOdd++;
}
}
System.out.println("Frequency of odd numbers: " + countOdd);
System.out.println("Frequency of even numbers: " + countEven);
}
}