Java Array Sum sumArray(int[] arr)

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

Description

Returns the sum of all values in an array.

License

Open Source License

Declaration

public static int sumArray(int[] arr) 

Method Source Code

//package com.java2s;

public class Main {
    /** Returns the sum of all values in an array. Args: Array */
    public static int sumArray(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];/*  w  w  w. j  a va  2 s  .c  o  m*/
        }
        return sum;
    }

    /** Returns the sum of all values in an array. Args: Array */
    public static double sumArray(double[] arr) {
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }

    /** Returns the sum of all values in an array. Args: Array */
    public static float sumArray(float[] arr) {
        float sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }

    public static long sumArray(long[] arr) {
        long sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }
}

Related

  1. sumandsub(String[] X)
  2. sumArray(double inputArray[])
  3. sumArray(double[] array)
  4. sumArray(double[] array)
  5. sumArray(int Array[])
  6. sumArray(int[] array)
  7. sumArray(short[] array)
  8. sumArrays(double[] xs1, double[] xs2)
  9. sumaTotal(int vector[])