-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrices_add.java
More file actions
36 lines (36 loc) · 1.12 KB
/
matrices_add.java
File metadata and controls
36 lines (36 loc) · 1.12 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
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter row");
int r=sc.nextInt();
System.out.println("Enter col");
int c=sc.nextInt();
if(r!=c){
System.out.print("size should be same");
}else if(r<0||c<0){
System.out.print("Array size should not be negative");
}else{
int mat1[][]=new int[r][c];
int mat2[][]=new int[r][c];
int result[][]=new int[r][c];
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
mat1[i][j]=sc.nextInt();
}
}
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
mat1[i][j]=sc.nextInt();
}
}
System.out.println("Result:");
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
result[i][j]=mat1[i][j]+mat2[i][j];
}
}
System.out.println(""+result);
}
}
}