Compute the mean of double array - Java java.lang

Java examples for java.lang:double

Description

Compute the mean of double array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double[] series = new double[] { 34.45, 35.45, 36.67, 37.78,
                37.0000, 37.1234, 67.2344, 68.34534, 69.87700 };
        System.out.println(mean(series));
    }//from   w w w.jav  a  2s . c o  m

    /**
     * Compute the mean of the timeseries.
     * 
     * @param series The input timeseries.
     * @return the mean of values.
     */
    public static double mean(double[] series) {
        double res = 0D;
        for (int i = 0; i < series.length; i++) {
            res += series[i];
        }
        return res / ((Integer) series.length).doubleValue();
    }
}

Related Tutorials