-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubtractionarray.java
More file actions
31 lines (28 loc) · 1 KB
/
subtractionarray.java
File metadata and controls
31 lines (28 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
// difference of two arrays array1-array2
import java.util.Scanner;
public class subtractionarray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of the arrays: ");
int size = sc.nextInt();
int[] array1 = new int[size];
int[] array2 = new int[size];
int[] sumArray = new int[size];
System.out.println("Enter elements of first array:");
for (int i = 0; i < size; i++) {
array1[i] = sc.nextInt();
}
System.out.println("Enter elements of second array:");
for (int i = 0; i < size; i++) {
array2[i] = sc.nextInt();
}
for (int i = 0; i < size; i++) {
sumArray[i] = array1[i] - array2[i];
}
System.out.println("Resultant array after addition:");
for (int i = 0; i < size; i++) {
System.out.print(sumArray[i] + " ");
}
sc.close();
}
}