-
Notifications
You must be signed in to change notification settings - Fork 0
/
Two_Matrix_Sum.java
43 lines (33 loc) · 1.19 KB
/
Two_Matrix_Sum.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
import java.util.Scanner;
public class Two_Matrix_Sum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of a row in an array: ");
int n = sc.nextInt();
System.out.print("Enter the size of a coloumn in an array: ");
int m = sc.nextInt();
int[][] a = new int[n][m];
int[][] b = new int[n][m];
int[][] c = new int[n][m];
System.out.print("Enter elements in a first matrix: ");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = sc.nextInt();
}
}
System.out.print("Enter elements in a Second matrix: ");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
b[i][j] = sc.nextInt();
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
c[i][j] = a[i][j] + b[i][j];
System.out.print(" "+c[i][j]);
}
System.out.println();
}
sc.close();
}
}