-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySum2.java
More file actions
35 lines (27 loc) · 876 Bytes
/
Copy pathArraySum2.java
File metadata and controls
35 lines (27 loc) · 876 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
import java.util.Arrays;
public class ArraySum2 {
public static void main(String... args) {
int[] numbers = {5, 6, 1, 1, 11};
int totalSum = 0;
for (int number : numbers) {
totalSum += number;
}
int[] sums = new int[numbers.length];
for (int index = 0; index < numbers.length; index++) {
sums[index] = totalSum - numbers[index];
}
System.out.printf("%s%n", Arrays.toString(sums));
int minimum = sums[0];
int maximum = sums[0];
for (int sum : sums) {
if (sum < minimum) {
minimum = sum;
}
if (sum > maximum) {
maximum = sum;
}
}
int[] result = {minimum, maximum};
System.out.println(Arrays.toString(result));
}
}