-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixAddition.java
More file actions
31 lines (28 loc) · 851 Bytes
/
MatrixAddition.java
File metadata and controls
31 lines (28 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class MatrixAddition {
public static void main(String[] args) {
//Declaration & initialization of 2X3 matrix
int[][] matrix1 = {
{1,2,3},
{4,5,6}
};
int[][] matrix2 = {
{7,8,9},
{10,11,12}
};
//Declaration & initialization of Blank Matrix
int[][] resultMatrix = new int[2][3];
//Outer loop for row and inner for column - matrix addition
for(int i=0;i<2;i++){
for(int j=0;j<3;j++){
resultMatrix[i][j] = matrix1[i][j] + matrix2[i][j];
}
}
//Matrix Printing
for(int i=0;i<2;i++){
for(int j=0;j<3;j++){
System.out.print(resultMatrix[i][j] + " ");
}
System.out.println();
}
}
}