File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
InterviewPrograms/src/com/java/matrix Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .java .matrix ;
2+
3+ public class MatrixAddition {
4+
5+ public static void main (String [] args ) {
6+ int matrixA [][] = {
7+ {1 ,2 ,3 ,4 },
8+ {5 ,6 ,7 ,8 },
9+ {9 ,10 ,11 ,12 },
10+ {13 ,14 ,15 ,16 }
11+ };
12+
13+ int matrixB [][] = {
14+ {5 ,10 ,15 ,20 },
15+ {25 ,30 ,35 ,40 },
16+ {45 ,50 ,55 ,60 },
17+ {65 ,70 ,75 ,80 }
18+ };
19+ int rows = 4 ;
20+ int columns = 4 ;
21+
22+ int resultMatrix [][] = new int [rows ][columns ];
23+ for (int i =0 ;i <rows ;i ++)
24+ for (int j =0 ;j <columns ;j ++)
25+ resultMatrix [i ][j ] = matrixA [i ][j ] + matrixB [i ][j ];
26+
27+ System .out .println ("Addition of two matrix is ::" );
28+ for (int i =0 ;i <rows ;i ++){
29+ for (int j =0 ;j <columns ;j ++)
30+ System .out .print (resultMatrix [i ][j ]+" " );
31+ System .out .println ();
32+ }
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments