how to solve the average task I am not get proper solution for it

Viewed 45

The function mean should take an array of numbers and compute their arithmetic mean. For example, given an array containing 50 and 40 then mean should return 45. Complete the implementation of this function.

1 Answers

You can used java stream to calculate the avg.

public double getAverage(int[] arr) {
    return Arrays.stream(arr).average().orElse(Double.NaN);
}
Related