Java Array Average average(double[] array)

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

Description

average

License

Open Source License

Declaration

public static double average(double[] array) 

Method Source Code

//package com.java2s;
/*/*from   ww  w.  j  ava2 s  .c  o  m*/
 *
 *  Managed Data Structures
 *  Copyright ? 2016 Hewlett Packard Enterprise Development Company LP.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  As an exception, the copyright holders of this Library grant you permission
 *  to (i) compile an Application with the Library, and (ii) distribute the 
 *  Application containing code generated by the Library and added to the 
 *  Application during this compilation process under terms of your choice, 
 *  provided you also meet the terms and conditions of the Application license.
 *
 */

public class Main {
    public static double average(double[] array) {
        return average(array, array.length);
    }

    public static double average(double[] array, int len) {
        return sum(array, len) / len;
    }

    public static double sum(double[] array) {
        return sum(array, array.length);
    }

    public static double sum(double[] array, int len) {
        double sum = 0;
        for (int i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static int sum(int[] array) {
        return sum(array, array.length);
    }

    public static int sum(int[] array, int len) {
        int sum = 0;
        for (int i = 0; i < len; i++) {
            sum += array[i];
        }
        return sum;
    }
}

Related

  1. average(double... vals)
  2. average(double[] a)
  3. average(double[] a)
  4. average(Double[] arr)
  5. average(double[] array)
  6. average(double[] d)
  7. average(double[] values)
  8. average(double[] values)
  9. average(double[] values)