Java mean mean(Double[] a)

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

Description

mean

License

Open Source License

Declaration

public static Double mean(Double[] a) 

Method Source Code

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

public class Main {
    public static Double mean(Double[] a) {
        if (a.length == 0) {
            throw new IllegalArgumentException("The entered array is empty.");
        }//from w ww.j a  va 2s  .  co m
        Double sum = 0.0;
        for (int n = 0; n < a.length; n++) {
            sum += a[n];
        }
        return sum / a.length;
    }

    public static double mean(double[] a) {
        if (a.length == 0) {
            throw new IllegalArgumentException("The entered array is empty.");
        }
        double sum = 0.0;
        for (int n = 0; n < a.length; n++) {
            sum += a[n];
        }
        return sum / a.length;
    }

    public static Double mean(Integer[] a) {
        if (a.length == 0) {
            throw new IllegalArgumentException("The entered array is empty.");
        }
        Double[] a_d = new Double[a.length];
        for (int n = 0; n < a_d.length; n++) {
            a_d[n] = Double.valueOf(a[n]);
        }
        return mean(a_d);
    }

    public static double mean(int[] a) {
        if (a.length == 0) {
            throw new IllegalArgumentException("The entered array is empty.");
        }
        double[] a_d = new double[a.length];
        for (int n = 0; n < a_d.length; n++) {
            a_d[n] = a[n];
        }
        return mean(a_d);
    }
}

Related

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