-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayAddition.java
40 lines (37 loc) · 1022 Bytes
/
ArrayAddition.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
import java.util.Scanner;
public class ArrayAddition {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sn=new Scanner(System.in);
System.out.println("Enter the array row and column size");
int rSize = sn.nextInt();
int cSize = sn.nextInt();
int[][] array1 = new int[rSize][cSize];
System.out.println("Enter the 1st array values");
for(int i=0; i<rSize; i++) {
for(int j=0; j<cSize; j++) {
array1[i][j]=sn.nextInt();
}
}
int[][] array2 = new int[rSize][cSize];
System.out.println("Enter the 2nd array values");
for(int i=0; i<rSize; i++) {
for(int j=0; j<cSize; j++) {
array2[i][j]=sn.nextInt();
}
}
//array addition
int[][] sum=new int[rSize][cSize];
for(int i=0; i<rSize; i++) {
for(int j=0; j<cSize; j++) {
sum[i][j]=array1[i][j] + array2[i][j];
}
}
for(int[] result : sum ) {
for(int add : result) {
System.out.print(add+" ");
}
System.out.println();
}
}
}