Here you can find the source of average(int[] pixels)
public static int average(int[] pixels)
//package com.java2s; public class Main { public static int average(int[] pixels) { float m = 0; for (int i = 0; i < pixels.length; ++i) { m += pixels[i];/*from w w w. java2 s . co m*/ } m = m / pixels.length; return (int) m; } public static int average(double[] pixels) { float m = 0; for (int i = 0; i < pixels.length; ++i) { m += pixels[i]; } m = m / pixels.length; return (int) m; } }