-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddMatrix.java
More file actions
49 lines (38 loc) · 1 KB
/
AddMatrix.java
File metadata and controls
49 lines (38 loc) · 1 KB
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
47
48
49
package pkg;
import java.util.Scanner;
public class AddMatrix {
int row,col;
public static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("lease enter row and column");
int row= sc.nextInt();
int col= sc.nextInt();
int a[][] = new int[row][col];
int b[][]= new int [row][col];
int c[][]= new int[row][col];
System.out.println("please enter value of the 1st matrix");
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
a[i][j]= sc.nextInt();
}
}
System.out.println("please enter value of the 2snd matrix");
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
b[i][j]= sc.nextInt();
}
}
System.out.println("the sum of matrix is");
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
c[i][j]=a[i][j]+b[i][j];
}
}
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}