Java Array Sum sum(final double[] target)

Here you can find the source of sum(final double[] target)

Description

Returns the sum of target.

License

BSD License

Declaration

public static final double sum(final double[] target) 

Method Source Code

//package com.java2s;
/**// www.  j av a2s  .c  o  m
 *
 * This file is part of jReality. jReality is open source software, made
 * available under a BSD license:
 *
 * Copyright (c) 2003-2006, jReality Group: Charles Gunn, Tim Hoffmann, Markus
 * Schmies, Steffen Weissmann.
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * - Neither the name of jReality nor the names of its contributors nor the
 *   names of their associated organizations may be used to endorse or promote
 *   products derived from this software without specific prior written
 *   permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

public class Main {
    /** Returns the sum of <i>target</i>. */
    public static final double sum(final double[] target) {
        return sum(target, 0, target.length);
    }

    /** Returns the sum of <i>target</i> from <i>postion</i> to <i>postion+length-1</i>. */
    public static final double sum(final double[] target, final int position, final int length) {
        double sum = 0;
        for (int i = position; i < position + length; i++)
            sum += target[i];
        return sum;
    }

    /** Returns the sum of <i>target</i>. */
    public static final float sum(final float[] target) {
        return sum(target, 0, target.length);
    }

    /** Returns the sum of <i>target</i> from <i>postion</i> to <i>postion+length-1</i>. */
    public static final float sum(final float[] target, final int position, final int length) {
        float sum = 0;
        for (int i = position; i < position + length; i++)
            sum += target[i];
        return sum;
    }

    /** Returns the sum of <i>target</i>. */
    public static final int sum(final int[] target) {
        return sum(target, 0, target.length);
    }

    /** Returns the sum of <i>target</i> from <i>postion</i> to <i>postion+length-1</i>. */
    public static final int sum(final int[] target, final int position, final int length) {
        int sum = 0;
        for (int i = position; i < position + length; i++)
            sum += target[i];
        return sum;
    }
}

Related

  1. sum(final double[] arr)
  2. sum(final double[] array)
  3. sum(final double[] decay, final int factor)
  4. sum(final Double[] doubles)
  5. sum(final double[] productMix)
  6. sum(final double[] vec)
  7. sum(final float[] x)
  8. sum(final int base, final int[] ints)
  9. sum(final int[] terms, final int start, final int len)