-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySum.java
More file actions
52 lines (33 loc) · 862 Bytes
/
Copy pathArraySum.java
File metadata and controls
52 lines (33 loc) · 862 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
45
46
47
48
49
50
51
52
import java.util.Arrays;
public class ArraySum{
public static void main(String... args){
int[] numbers = {5, 6, 1, 1, 11};
int[] sums =new int[numbers.length];
int store ;
int sum;
for(int index = 0; index < numbers.length; index++){
store = numbers[index];
sum = 0;
for(int count =0; count < numbers.length; count++){
if (numbers[count] != store)
sum += numbers[count];
}
sums [index] = sum;
}
System.out.printf("%s%n", Arrays.toString(sums));
int[] result =new int[2];
int minimum = sums[0];
int maximum = sums[0];
for(int counter = 0; counter < sums.length; counter++){
if(maximum < sums[counter]){
maximum = sums[counter];
}
if(minimum > sums[counter]){
minimum = sums[counter];
}
result[0] = minimum;
result[1] = maximum;
}
System.out.println(Arrays.toString(result));
}
}