-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_arrayMethods.java
More file actions
44 lines (28 loc) · 1012 Bytes
/
Copy path_arrayMethods.java
File metadata and controls
44 lines (28 loc) · 1012 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
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
public class _arrayMethods{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int array1 [] = new int[4];
int array2 [] = new int[4];
System.out.println("Enter the numbers of 1st array ");
for(int i =0; i<array1.length;i++){
array1[i] = sc.nextInt();
}
System.out.println("Enter the numbers of 2nd array ");
for(int i =0;i<array2.length;i++){
array2[i]= sc.nextInt();
}
System.out.println("The sum of these two arrays is ");
sumOfTwo(array1, array2);
sc.close();
}
public static void sumOfTwo(int array1[] , int array2[]){
int result[] = new int[array1.length];
for(int i = 0; i<array1.length; i++){
result[i] = array1[i] + array2[i];
}
for(int i =0; i<result.length;i++){
System.out.println(result[i] + " ");
}
}
}