Java Array Sum sumValues(double[] vector)

Here you can find the source of sumValues(double[] vector)

Description

Compute the sum of values in an array

License

Open Source License

Parameter

Parameter Description
vector a parameter

Return

the sum of all values

Declaration

public static double sumValues(double[] vector) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w  w  w  . j a  va 2 s. com
     * Compute the sum of values in an array
     * @param vector
     * @return the sum of all values
     */
    public static double sumValues(double[] vector) {
        double sum = 0;

        for (double v : vector)
            sum += v;

        return sum;
    }

    /**
     * Compute the sum of values in an array
     * @param vector
     * @return the sum of all values
     */
    public static float sumValues(float[] vector) {
        float sum = 0;

        for (float v : vector)
            sum += v;

        return sum;
    }

    /**
     * Compute the sum of values in an array
     * @param vector
     * @return the sum of all values
     */
    public static int sumValues(int[] vector) {
        int sum = 0;

        for (int v : vector)
            sum += v;

        return sum;
    }

    /**
     * Compute the sum of values in an array
     * @param vector
     * @return the sum of all values
     */
    public static int sumValues(byte[] vector) {
        int sum = 0;

        for (int v : vector)
            sum += v;

        return sum;
    }

    /**
     * Compute the sum of values in an array
     * @param vector
     * @return the sum of all values
     */
    public static int sumValues(short[] vector) {
        int sum = 0;

        for (int v : vector)
            sum += v;

        return sum;
    }

    /**
     * Compute the sum of values in an array
     * @param vector
     * @return the sum of all values
     */
    public static long sumValues(long[] vector) {
        long sum = 0;

        for (long v : vector)
            sum += v;

        return sum;
    }
}

Related

  1. sumRightShifts(int num, int... shifts)
  2. sumSquared(double[] a)
  3. sumToDouble(float[] array)
  4. sumToLong(byte[] array)
  5. sumUpArray(int[] array)