Here you can find the source of mean(double[] samples)
public static double mean(double[] samples) throws Exception
//package com.java2s; public class Main { public static double mean(double[] samples) throws Exception { return mean(samples, 0, samples.length); }/*from www. j a v a2 s .c o m*/ public static double mean(double[] samples, int fromIndex, int toIndex) throws Exception { if (samples.length == 0) { throw new Exception("Empty array to calculate mean"); } if (fromIndex < 0 || fromIndex >= samples.length || toIndex < 0 || toIndex >= samples.length) { throw new IndexOutOfBoundsException(); } double meanValue = 0; for (int i = fromIndex; i <= toIndex; i++) { meanValue += samples[i]; } return meanValue / (toIndex - fromIndex + 1); } }