Java Array Sum sum( int[] a)

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

Description

sum

License

Open Source License

Declaration

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

Method Source Code

//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;
        }
    }
}

Related

  1. arraySum(final double input[])
  2. ArraySum(float[] a)
  3. arraySum(int[] intArray, short flag)
  4. getSum(int[] array)
  5. getSum(int[] array)
  6. sum(byte... bytes)
  7. sum(byte[] array)
  8. sum(byte[] array)
  9. sum(byte[] array, int offset, int size)