Here you can find the source of sum( int[] a)
public static int sum( int[] a) throws Exception
//package com.java2s; //License from project: Open Source License public class Main { public static int sum(/*@ nullable @*/ int[] a) throws Exception { if (a == null) throw new Exception("Array is null."); else {/*from w w w. j a v a2s .c om*/ 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; } } }