-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathArray5.java
More file actions
35 lines (30 loc) · 700 Bytes
/
Array5.java
File metadata and controls
35 lines (30 loc) · 700 Bytes
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
package Day3;
public class Array5 {
private static void sum(int[] arr1, int[] arr2) {
int len = 0;
if (arr1.length > arr2.length)
len = arr1.length;
else {
len = arr2.length;
}
System.out.println("Length: " + len);
int[] sum = new int[len];
for (int i = 0; i < len; i++) {
sum[i] = arr1[i] + arr2[i];
}
System.out.println("Sum of two Arrays");
for (int i : sum) {
System.out.print(i + " ");
}
}
public static void main(String[] args) {
int[] arr1 = { 2, 4, 6, 8, 10 };
int[] arr2 = { 1, 3, 5, 7,8 };
try {
sum(arr1, arr2);
} catch (Exception e) {
// TODO Auto-generated catch block
System.err.println("Please choose exact length");
}
}
}