computes the mean of a passed double array - Android java.lang

Android examples for java.lang:array calculation

Description

computes the mean of a passed double array

Demo Code


//package com.java2s;

public class Main {
    /**//from  w w  w .  ja va2  s  . c  o m
     * computes the mean of a passed double array
     * @param _arr the array to compute the mean from
     * @return the mean of the passed double array
     */
    public static double mean(double[] _arr) {
        double sum = 0;

        for (double d : _arr) {
            sum += d;
        }
        return sum / _arr.length;
    }
}

Related Tutorials