Java Array Average average(int[] a)

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

Description

average

License

Open Source License

Declaration

public static int average(int[] a) throws Exception 

Method Source Code

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

public class Main {
    public static int average(int[] a) throws Exception {
        int sum = sum(a);
        return sum / a.length;
    }//from  w ww. j  a  va  2s  . c  om

    public static int sum(/*@ nullable @*/ int[] a) throws Exception {
        if (a == null)
            throw new Exception("Array is null.");
        else {
            int sum = 0;
            /*@ loop_invariant i >= 0 && i <= a.length;
              @ loop_invariant sum == (\sum int j; 0 <= j && j < i; a[j]);
              @ decreasing a.length - i;
              @ assignable sum, i;
              @*/
            for (int i = 0; i < a.length; i++)
                sum += a[i];
            return sum;
        }
    }
}

Related

  1. average(float[][] data, int startIndex, int endIndex)
  2. average(float[][] originalValues, float[][] newValues, int[] indexArray)
  3. average(int argb0, int argb1)
  4. average(int... is)
  5. average(int... values)
  6. average(int[] array)
  7. average(int[] pixels)
  8. average(int[] pixels)
  9. average(int[] x)