Java Array Sum getSum(int[] array)

Here you can find the source of getSum(int[] array)

Description

get Sum

License

Open Source License

Declaration

public static int getSum(int[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static double getSum(Collection<? extends Number> values) {
        double sm = 0;
        for (Number value : values) {
            sm += value.doubleValue();//from  w w w  .  j  a v  a  2s .c  o m
        }
        return sm;
    }

    public static int getSum(int[] array) {
        // return sum of all elements in array
        int sum = 0;
        for (int val : array)
            sum += val;
        return sum;
    }

    public static float getSum(float[] array) {
        // return sum of all elements in array
        float sum = 0;
        for (float val : array)
            sum += val;
        return sum;
    }

    public static double getSum(double[] array) {
        // return sum of all elements in array
        double sum = 0;
        for (double val : array)
            sum += val;
        return sum;
    }

    public static Integer getSum(Integer[] array) {
        Integer sm = 0;
        for (Integer value : array)
            sm += value;
        return sm;
    }

    public static float getSum(float[][][] array) {
        // return array of three-dimensional double array
        float sm = 0;
        for (float[][] anArray : array) {
            for (int i = 0; i < array[0][0].length; i++) {
                for (int j = 0; j < array[0].length; j++)
                    sm += anArray[i][j];
            }
        }
        return sm;
    }
}

Related

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