[POO] sum and media added to MathTools

This commit is contained in:
TiagoRG 2023-05-08 17:35:21 +01:00
parent 1d0b4e460d
commit d4cf6f0bbd
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
1 changed files with 12 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package utils;
import java.util.List;
import java.util.Random;
public class MathTools {
@ -20,4 +21,15 @@ public class MathTools {
return false;
return true;
}
public static double sum(List<Double> list) {
double sum = 0;
for (double n : list)
sum += n;
return sum;
}
public static double media(List<Double> list) {
return sum(list) / list.size();
}
}