Here you can find the source of Mean(ArrayList
Parameter | Description |
---|---|
values | List of numeric values |
Parameter | Description |
---|---|
Exception | an exception |
public static double Mean(ArrayList<Double> values) throws Exception
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.util.*; public class Main { /** Calculates the mean (average) value from a list of numeric values. *// w w w . j ava 2 s. c o m * @param values List of numeric values * @return Mean (average) value * @throws Exception */ public static double Mean(ArrayList<Double> values) throws Exception { if (values.size() == 0) throw new Exception("Cannot determine mean on an empty list."); return Sum(values) / (double) values.size(); } /** Calculates the sum of a list of numeric values. * * @param values List of numeric values * @return Summed value */ public static double Sum(ArrayList<Double> values) { double sum = 0.0; for (double value : values) sum += value; return sum; } }