Skip to content

Commit 0ad90b3

Browse files
committed
Addition of two matrix
1 parent 660c942 commit 0ad90b3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)