Java Array Sum sum(int[] arr)

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

Description

sum

License

Open Source License

Declaration

public static int sum(int[] arr) 

Method Source Code

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

Related

  1. sum(int[] a)
  2. sum(int[] a)
  3. sum(int[] a)
  4. sum(int[] a)
  5. sum(int[] add)
  6. sum(int[] arr)
  7. sum(int[] arr)
  8. sum(int[] arr)
  9. sum(int[] array)