Java Array Average average(double[] a)

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

Description

average

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 average(double[] a) 

Method Source Code

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

public class Main {
    /**//from www.j  a  va 2 s.  com
     * @param a The array to calculate the average for.
     * @return The average over all elements in the array.
     */
    public static double average(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. average(double values[])
  2. average(double x, double y)
  3. average(double x1, double x2)
  4. average(double... args)
  5. average(double... vals)
  6. average(double[] a)
  7. average(Double[] arr)
  8. average(double[] array)
  9. average(double[] array)