Question

# Find the frequency of odd number elements in the given Matrix.

ENTER THE ROW OF MATRIX
3
ENTER THE COLUMN OF MATRIX
3
ENTER THE ELEMENTS IN MATRIX
1
2
3
4
5
6
7
8
9
FREQUENCY OF ODD NUMBER IN MATRIX: 5

# Share code with your friends

Code

import java.util.Scanner;
public class FrequencyOfOddNumberInMatrix
{
public static void main(String[] args)
{
int row=0, col=0,count=0,i=0,j=0;
int a[][];

Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE ROW OF MATRIX");
row=sc.nextInt();
System.out.println("ENTER THE COLUMN OF MATRIX");
col=sc.nextInt();

a=new int[row][col];
System.out.println("ENTER THE ELEMENTS IN MATRIX");
for(i=0;i< row;i++)
{
for(j=0;j< col;j++)
{
a[i][j]=sc.nextInt();
}
}

/*if a[i][j]%2!=0 then increment 'count' by 1*/

for(i=0;i< row;i++)
{
for(j=0;j< col;j++)
{
if(a[i][j]%2!=0)
{
count++;

}

}
}
System.out.println("FREQUENCY OF ODD NUMBER IN MATRIX: "+count);
}
}

Sale

50
Sale

150
Sale

200
Sale

50
Sale

50
Sale

50
Sale

50
Sale

50
Sale

50