-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZeroMath.java
39 lines (33 loc) · 1.01 KB
/
ZeroMath.java
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
package zeroPackage;
import java.lang.Math;
public class ZeroMath {
public static double arraySum(double[] array) {
double sum = 0;
for (double value : array) {
sum += value;
}
return sum;
}
public static double arraySumPos(double[] array) {
double posSum = 0;
for (double value : array) {
posSum += Math.max(0.0, value);
}
return posSum;
}
public static double arraySumNeg(double[] array) {
double negSum = 0;
for (double value : array) {
negSum += Math.min(0.0, value);
}
return negSum;
}
public static double[] arrayMultiply(double[] array, double multiplier) { // Void because original array is
// modified!
// Test if this works properly!
for (int i = 0; i < array.length; i++) {
array[i] = array[i] * multiplier;
}
return array;
}
}