Here you can find the source of getAverage(double[] values)
Parameter | Description |
---|---|
values | the values to use |
public static double getAverage(double[] values)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**/*from w ww . j a va2s.c o m*/ * Calculate mean * @param values the values to use * @return mean */ public static double getAverage(double[] values) { return sum(values) / (double) values.length; } public static double getAverage(Collection<Double> values) { return sum(values) / (double) values.size(); } public static double sum(double[] values) { double sum = 0.0; for (int i = 0; i < values.length; i++) { sum += values[i]; } return sum; } /** * Calculate sum * @param values * @return */ public static double sum(Collection<Double> values) { double sum = 0.0; for (Double value : values) { sum += value; } return sum; } }