Sum of 2-D Array Java Program

Sum of matrix using 2-D array java program?

We all know about this word. Matrix is part of Engineering Mathematics. We calculate sum of matrix in Engineering Mathematics. Now we can also solve that problem in 2-D array java program too.

Using of this blog topic we can solve all matrix problems.

int x[3][3] = {{10,20,30},{40,50,60},{70,80,90}};

int y[3][3] = {{  1,   2,  3},{   4,  5,  6},{  7,  8,   9}}

 

In this blog example, we have to find some sum.

x[0][0] + y[2][2] = 10 + 9 => 19

x[0][1] + y[2][1] = 20 + 8 => 28

x[0][2] + y[2][0] = 30 + 7 => 37

………………

x[2][2] + y[0][0] = 90 + 1 => 91

 

So we can find cross sum of two values.

 

Let’s see how to work in program.

 

class arr8

{

            public static void main(String args[])

            {

 

                        int[][] x = new int[3][3];

                        int[][] y = new int[3][3];

 

                        x[0][0] = 10;

                        x[0][1] = 20;

                        x[0][2] = 30;

 

                        x[1][0] = 40;

                        x[1][1] = 50;

                        x[1][2] = 60;

 

                        x[2][0] = 70;

                        x[2][1] = 80;

                        x[2][2] = 90;                       

 

                        y[0][0] = 1;

                        y[0][1] = 2;

                        y[0][2] = 3;

 

                        y[1][0] = 4;

                        y[1][1] = 5;

                        y[1][2] = 6;

 

                        y[2][0] = 7;

                        y[2][1] = 8;

                        y[2][2] = 9;

 

 

                        for(int i=0;i<=2;i++)

                        {

                                    for(int j=0;j<=2;j++)

                                    {

                                                System.out.print((x[i][j]  + y[2-i][2-j]) + ” “);

                                    }

                                    System.out.println();

                        }          

            }

}

Output:

19 28 37

46 55 64

73 82 91

 

1343total visits,6visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

4 responses to “Sum of 2-D Array Java Program”

  1. I’m also commenting to make you be aware of what a outstanding encounter my cousin’s princess found browsing your web site. She realized lots of details, not to mention what it is like to possess an excellent helping mindset to get other folks effortlessly know certain complicated topics. You truly did more than my expected results. Thanks for producing such good, trustworthy, edifying and as well as easy tips about the topic to Ethel.

  2. Nice post. I be taught something more difficult on different blogs everyday. It would all the time be stimulating to read content from different writers and observe a bit of one thing from their store. I抎 want to make use of some with the content material on my blog whether or not you don抰 mind. Natually I抣l give you a hyperlink on your web blog. Thanks for sharing.