Welcome :Guest

Congratulations!!!

Top 5 Contributors of the Month
yasminpriya
Ram
Gaurav Pal
christianasteves

 Home >> Code Snippets >> Azure >> Post New Resource

# Java program to calculate matrix position.

Posted By:laptop charles       Posted Date: July 17, 2010    Points: 10    Category: Azure    URL: http://www.dotnetspark.com

Calculate matrix count and position.

Get 3*3 matrix.
And calculate the matrix value for odd numbers and then also calculate
the even values.
Sum of even and sum of odd values.
```import java.io.*;
class matoe
{
public static void main(String arg[])throws IOException
{
int sum=0,i,odd=0,even=0,j,k=0,l=0;

int a[][]=new int[3][3];

System.out.println("Enter the matrix");
System.out.println("----------------");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
}
}

System.out.println("The given matrix");
System.out.println("----------------");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
System.out.print(a[i][j]);
}
System.out.println(" ");
}

System.out.println("The odd no's");
System.out.println("------------");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(a[i][j]%2==1)

{
System.out.println(a[i][j]);
odd=odd+a[i][j];
k++;
}
else
{
even=even+a[i][j];
l++;
}
}
}
System.out.println("The even no's");
System.out.println("-------------");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(a[i][j]%2==0)
{
System.out.println(a[i][j]);
}
}
}

System.out.println("The odd no's counted");
System.out.println("--------------------");
System.out.println("The no of ODD is="+k);
System.out.println("The even no's counted");
System.out.println("---------------------");
System.out.println("The no of EVEN is="+l);
System.out.println("-------------------");
System.out.println("The sum of ODD is="+odd);

System.out.println("--------------------");
System.out.println("The sum of EVEN is="+even);

}
}
```

Responses

No response found. Be the first to respond this post

Post Comment