computes the sum of all values of a passed double array - Android java.lang

Android examples for java.lang:array calculation

Description

computes the sum of all values of a passed double array

Demo Code


//package com.java2s;

public class Main {
    /**/*w  w w.  j ava2  s  . co m*/
     * computes the sum of all values of a passed double array
     * @param _vals the double array to compute the sum from
     * @return the sum of the elements of the passed array
     */
    public static double sum(double[] _vals) {
        double sum = 0;
        for (int i = 0; i < _vals.length; i++) {
            sum += _vals[i];
        }
        return sum;
    }
}

Related Tutorials