Java mean mean(double[] v)

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

Description

Computes the mean.

License

Open Source License

Declaration

public static double mean(double[] v) 

Method Source Code

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

public class Main {
    /**//from   w  w  w.  j  a va  2 s  .  c o  m
     * Computes the mean.
     */
    public static double mean(double[] v) {
        if (v.length == 0)
            throw new IllegalArgumentException("Nothing to compute! The array must have at least one element.");
        return (mass(v) / (double) v.length);
    }

    /**
     * Computes the mean.
     */
    public static double mean(int[] v) {
        if (v.length == 0)
            throw new IllegalArgumentException("Nothing to compute! The array must have at least one element.");
        return (mass(v) / (double) v.length);
    }

    /**
     * Returns the sum of the elements of the array.
     */
    public static double mass(double[] v) {
        double somme = 0.0;
        for (int k = 0; k < v.length; k++) {
            somme += v[k];
        }
        return (somme);
    }

    /**
     * Returns the sum of the elements of the array.
     */
    public static int mass(int[] v) {
        int somme = 0;
        for (int k = 0; k < v.length; k++) {
            somme += v[k];
        }
        return (somme);
    }
}

Related

  1. mean(double[] doubleArray)
  2. mean(double[] list)
  3. mean(double[] nums)
  4. mean(double[] samples)
  5. mean(double[] series)
  6. mean(double[] values)
  7. mean(double[] vector)
  8. mean(double[] x, boolean[] used)
  9. mean(double[][] image)