-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixAddition.java
46 lines (36 loc) · 944 Bytes
/
MatrixAddition.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class matrix_addition {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int arr1[][] = new int[2][3];
System.out.println("matrix addition");
System.out.println("Enter some values: ");
for(int x = 0;x<2;x++) {
for(int y = 0;y<3;y++) {
arr1[x][y] = scan.nextInt();
}
}
int arr2[][] = new int[2][3];
System.out.println("Enter some values");
for(int i = 0;i<2;i++) {
for(int j = 0;j<3;j++)
{
arr2[i][j] = scan.nextInt();
}
}
int sum[][]=new int[2][3];
for (int x = 0;x<2;x++) {
for(int y = 0;y<3;y++) {
sum[x][y] = arr1[x][y] + arr2[x][y];
}
}
System.out.println(" Here is the resultant Matxix");
for (int x = 0;x<2;x++) {
for(int y = 0;y<3;y++) {
System.out.print(" "+sum[x][y]);
}
System.out.println();
}
}
}