-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassWork.java
More file actions
78 lines (54 loc) · 1.54 KB
/
Copy pathClassWork.java
File metadata and controls
78 lines (54 loc) · 1.54 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
public class ClassWork{
public static void main(String... args){
int[] values = {5, 10, 2, 1, 7};
final int LOWEST_LARGEST = 2;
int[] lowestLargest = new int[LOWEST_LARGEST];
int[] valuesTotal = sumElements(values);
for(int index = 0; index < valuesTotal.length; index++){
System.out.printf("%d%s ", valuesTotal[index], (index < valuesTotal.length - 1) ? "," : "");
}
lowestLargest[0] = lowestNumber(valuesTotal);
lowestLargest[1] = largestNumber(valuesTotal);
}
public static int[] sumElements(int[] values){
int counter;
int[] finalValues = new int[values.length];
int[] copy = new int[values.length -1];
for (int index = 0; index < values.length; index++){
counter = 0;
int total = 0;
for (int count =0; count < values.length; count++){
if (values[index] == values[count]){
continue;
}
else{
copy[counter] = values[count];
counter++;
}
}
for (int num = 0; num < copy.length; num++){
total+= copy[num];
}
finalValues[index] = total;
}
return finalValues;
}
public static int lowestNumber(int[] valuesTotal){
int lowest = valuesTotal[0];
for(int index = 1; index < valuesTotal.length; index++){
if (lowest > valuesTotal[index]){
lowest = valuesTotal[index];
}
}
return lowest;
}
public static int largestNumber(int[] valuesTotal){
int largest = valuesTotal[0];
for(int index = 1; index < valuesTotal.length; index++){
if (largest < valuesTotal[index]){
largest = valuesTotal[index];
}
}
return largest;
}
}