Java Array Sum sum(float[] array)

Here you can find the source of sum(float[] array)

Description

Sums all elements of array

License

Open Source License

Parameter

Parameter Description
array a parameter

Declaration

public static float sum(float[] array) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w.j  a v  a  2  s.co m*/
 * Copyright (c) 2008-2013 Maksim Khadkevich and Fondazione Bruno Kessler.
 *
 * This file is part of MART.
 * MART is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2, as published
 * by the Free Software Foundation.
 *
 * MART is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with MART; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

public class Main {
    /**
     * Sums all elements of array
     *
     * @param array
     * @return
     */
    public static float sum(float[] array) {
        float sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }

        return sum;
    }

    /**
     * Sums all elements of array
     *
     * @param array
     * @return
     */
    public static double sum(double[] array) {
        double sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }

        return sum;
    }

    /**
     * Sums all elements of array
     *
     * @param array
     * @return
     */
    public static float sum(float[] array, int startIndex, int endIndex) {
        float sum = 0;
        for (int i = startIndex; i < endIndex; i++) {
            sum += array[i];
        }

        return sum;
    }

    /**
     * Sums all elements of array
     *
     * @param array
     * @return
     */
    public static double sum(double[] array, int startIndex, int endIndex) {
        double sum = 0;
        for (int i = startIndex; i < endIndex; i++) {
            sum += array[i];
        }

        return sum;
    }

    /**
     * Sums all elements of array
     *
     * @param array
     * @return
     */
    public static int sum(int[] array) {
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }

        return sum;
    }
}

Related

  1. sum(final int[] terms, final int start, final int len)
  2. sum(final int[] values)
  3. sum(final int[] values, final int... indice)
  4. sum(final long... values)
  5. sum(float[] a, int off, int length)
  6. sum(float[] distribution)
  7. sum(float[] items, int offset, int length)
  8. sum(float[] vector)
  9. sum(int... values)