Here you can find the source of sum(int[] arr)
Parameter | Description |
---|---|
arr | the array to be SUM |
public static int sum(int[] arr)
//package com.java2s; //License from project: Open Source License public class Main { public static int sum(int[] arr) { int sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i];//from w ww. j av a 2s . c o m } return sum; } public static double sum(double[] arr) { double sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static float sum(float[] arr) { float sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static long sum(long[] arr) { long sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static short sum(short[] arr) { short sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } public static byte sum(byte[] arr) { byte sum = 0; for (int i = 0, l = arr.length; i < l; i++) { sum += arr[i]; } return sum; } }