Here you can find the source of sum(int[] arr)
public static int sum(int[] arr)
//package com.java2s; //License from project: Open Source License public class Main { public static int sum(int[] arr) { if (arr == null || arr.length == 0) return 0; int l = arr.length; int res = 0; for (int i = 0; i < l; i++) { res += arr[i];//from w w w . ja va2 s . co m } return res; } public static double sum(double[] arr) { if (arr == null || arr.length == 0) return 0; int l = arr.length; double res = 0; for (int i = 0; i < l; i++) { res += arr[i]; } return res; } }