Here you can find the source of average(int[] a)
public static int average(int[] a) throws Exception
//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; } } }