Java mean mean(double[] a)

Here you can find the source of mean(double[] a)

Description

mean

License

Open Source License

Parameter

Parameter Description
a The array to calculate the average for.

Return

The average over all elements in the array.

Declaration

public static double mean(double[] a) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w w w  .  j av a2  s. c  o  m*/
     * @param a The array to calculate the average for.
     * @return The average over all elements in the array.
     */
    public static double mean(double[] a) {
        return sum(a) / a.length;
    }

    /**
     * @param a The array to sum.
     * @return The sum over all elements in the array.
     */
    public static double sum(double[] a) {
        double sum = 0;
        for (int i = 0; i < a.length; i++)
            sum += a[i];
        return sum;
    }

    /**
     * @param a The array to sum.
     * @return The sum over all elements in the array.
     */
    public static long sum(int[] a) {
        long sum = 0;
        for (int i = 0; i < a.length; i++)
            sum += a[i];
        return sum;
    }
}

Related

  1. mean(Double totalValue, int numValues)
  2. mean(double v1, double v2)
  3. mean(double values[])
  4. mean(Double[] a)
  5. mean(double[] a)
  6. mean(double[] a)
  7. mean(double[] a, double[] b)
  8. mean(double[] a, double[] b)
  9. mean(double[] a, int from, int to)