Here you can find the source of average(double... vals)
Parameter | Description |
---|---|
vals | a parameter |
public static double average(double... vals)
//package com.java2s; /**//from www . j a va2 s . c om * <p> * Useful math functions. :) * </p> * <p> * <span class="BSDLicense"> This software is distributed under the <a * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>. </span> * </p> * * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu) */ public class Main { /** * If you think your values will overflow this operation, then roll your own * * @param vals * @return */ public static double average(double... vals) { if (vals == null || vals.length == 0) { return 0; } return sum(vals) / vals.length; } /** * @param vals * @return */ private static double sum(double... vals) { double sum = 0; for (double val : vals) { sum += val; } return sum; } }