-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathArrayUtils.java
More file actions
36 lines (31 loc) · 804 Bytes
/
Copy pathMathArrayUtils.java
File metadata and controls
36 lines (31 loc) · 804 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
package memory.ex;
public class MathArrayUtils {
private MathArrayUtils(){
}
public static int sum(int[] values) {
int total = 0;
for (int value : values) {
total += value;
}
return total;
}
public static double average(int[] values) {
return (double)sum(values) / values.length;
}
public static int min(int[] values) {
int minValue = values[0];
for (int value : values) {
if(minValue > value)
minValue = value;
}
return minValue;
}
public static int max(int[] values) {
int maxValue = values[0] ;
for (int value : values) {
if(maxValue < value)
maxValue = value;
}
return maxValue;
}
}