Java Array Sum Square sumValuesSquared(double[] vector)

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

Description

Compute the sum of values squared in an array

License

Open Source License

Parameter

Parameter Description
vector a parameter

Return

the sum of all values

Declaration

public static double sumValuesSquared(double[] vector) 

Method Source Code

//package com.java2s;

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

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

        return sum;
    }

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

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

        return sum;
    }

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

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

        return sum;
    }

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

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

        return sum;
    }

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

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

        return sum;
    }

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

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

        return sum;
    }
}

Related

  1. sumSquareDoubleArray(double[] v)
  2. sumSquares(double[] aArray)
  3. sumSquares(double[] data)
  4. sumSquares(final float[] a)
  5. sumSquares(float[] in)