Java Array Average average(int[] array)

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

Description

average

License

Open Source License

Declaration

public static double average(int[] array) 

Method Source Code

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

public class Main {
    public static double average(int[] array) {
        return sum(array) / array.length;
    }//from  w ww  .  j  a  v a 2s.c o m

    public static double average(int[][] matrix) {
        return sum(matrix) / (matrix.length * matrix[0].length);
    }

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

    public static int sum(int[][] array) {
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                sum += array[i][j];
            }
        }
        return sum;
    }
}

Related

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