Java Array Sum sumOf(int... values)

Here you can find the source of sumOf(int... values)

Description

Return the sum of all given Integer values

License

Apache License

Parameter

Parameter Description
values a parameter

Declaration

public static int sumOf(int... values) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2011 Danny Kunz/*ww w. j a v  a2  s  .  c  o  m*/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

public class Main {
    /**
     * Return the sum of all given {@link Integer} values
     * 
     * @param values
     * @return
     */
    public static int sumOf(int... values) {
        //
        int retval = 0;

        //
        for (int value : values) {
            retval += value;
        }

        //
        return retval;
    }
}

Related

  1. sumMaxK(double[] x, int k)
  2. summedDifference(int[][] matrix, short topX, short botX, short row)
  3. sumMinMax(double[] values, int out[])
  4. sumMult(double[] aArray1, double[] aArray2)
  5. sumNaive(final double... values)
  6. sumOfArray(double[] array)
  7. sumOfArray(final double[] array)
  8. sumOfMeanDifferencesOnePoint(double[] vector)
  9. sumOfMinimum(double[] a, double[] b)