-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassWorkMain.java
More file actions
88 lines (61 loc) · 2.37 KB
/
Copy pathClassWorkMain.java
File metadata and controls
88 lines (61 loc) · 2.37 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
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.Arrays;
public class ClassWorkMain {
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) ? "," : "");
}
System.out.println();
lowestLargest[0] = lowestNumber(valuesTotal);
lowestLargest[1] = largestNumber(valuesTotal);
System.out.println("Lowest & Largest: " + Arrays.toString(lowestLargest));
int[] valuesSquared = squareInteger(values);
Arrays.sort(valuesSquared);
System.out.println("Squared values in ascending order: ");
for (int index = 0; index < valuesSquared.length; index++) {
System.out.printf("%d%s ", valuesSquared[index], (index < valuesSquared.length - 1) ? "," : "");
}
System.out.println();
}
public static int[] sumElements(int[] values) {
int[] finalValues = new int[values.length];
for (int index = 0; index < values.length; index++) {
int total = 0;
for (int count = 0; count < values.length; count++) {
if (count != index) {
total += values[count];
}
}
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;
}
public static int[] squareInteger(int[] values){
int[] squaredValues = new int[values.length];
for (int index = 0; index < values.length; index++) {
squaredValues[index] = values[index] * values[index];
}
return squaredValues;
}
}