.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Azure >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

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];


BufferedReader n=new BufferedReader(new InputStreamReader(System.in));

          System.out.println("Enter the matrix");
          System.out.println("----------------");
          for(i=0;i<=2;i++)
             {
              for(j=0;j<=2;j++)
                 {
                  a[i][j]=Integer.parseInt(n.readLine());
                 }
             }

          
          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("addtion of odd no's");
System.out.println("-------------------");
System.out.println("The sum of ODD is="+odd);

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



}
}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Related Resource From The Same Category

Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend