-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram30.java
More file actions
29 lines (23 loc) · 749 Bytes
/
Program30.java
File metadata and controls
29 lines (23 loc) · 749 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
// Program 30
// Week 1 - Day 5
// Subtract of all the elements in the array
// imput: 1-2-3-4-5
// Output: -13
import java.util.*;
public class Program30 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of elements in the array: ");
int n = sc.nextInt();
int[] arr = new int[n];
System.out.println("Enter the elements of the array: ");
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int subtract = arr[0];
for (int i = 1; i < n; i++) {
subtract -= arr[i];
}
System.out.println("The subtract of all the elements in the array is: " + subtract);
}
}