Java Number Sum sum(Iterable as)

Here you can find the source of sum(Iterable as)

Description

The sum of a sequence of floating-point numbers

License

Open Source License

Parameter

Parameter Description
as an iterable of double values

Return

the sum of the double values

Declaration

public static double sum(Iterable<Double> as) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww  w  .  j  a  v a2 s .c o  m
     * The sum of a sequence of floating-point numbers
     *
     * @param as  an iterable of double values
     * @return the sum of the double values
     */
    public static double sum(Iterable<Double> as) {
        double sum = 0;
        for (double a : as) {
            sum += a;
        }
        return sum;
    }

    /**
     * The sum of an array of floating-point numbers
     *
     * @param as  an array of double values
     * @return the sum of the double values
     */
    public static double sum(double[] as) {
        double sum = 0;
        for (double a : as) {
            sum += a;
        }
        return sum;
    }
}

Related

  1. sum(double x, double y)
  2. sum(final Iterable values)
  3. sum(final Iterable ns)
  4. sum(int a, int b)
  5. sum(int matrix1, int matrix2)
  6. sum(Iterable iterable)
  7. sum(long space1, String space2)
  8. sum(long x, int c)
  9. sum(Number n1, Number n2)