Commit bd79c275 authored by hasan  khaddour's avatar hasan khaddour

Add Geometric Mean Task

parent 5c228c65
package task;
import java.util.Arrays;
public class TaskGeometricMean extends TaskImpl {
@Override
public void execute() {
String[] stringArray = input.split(",");
double[] doubleArray = Arrays.stream(stringArray)
.mapToDouble(Double::parseDouble)
.toArray();
// Calculate the geometric mean
double product = Arrays.stream(doubleArray).reduce(1.0, (a, b) -> a * b);
double geometricMean = Math.pow(product, 1.0 / doubleArray.length);
result = String.valueOf(geometricMean);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment