Here you can find the source of sum(long[] array)
Parameter | Description |
---|---|
array | Input array |
public static double sum(long[] array)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Pablo Pavon-Marino. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors:/* ww w. j av a2s . c om*/ * Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1 * Pablo Pavon-Marino - from version 0.4.0 onwards ******************************************************************************/ public class Main { /** * Returns the sum of all elements in the array. * * @param array Input array * @return Sum of all array elements * */ public static double sum(long[] array) { double out = 0; for (int i = 0; i < array.length; i++) { out += array[i]; } return out; } /** * Returns the element-wise sum of two arrays. * * @param array1 Input array 1 * @param array2 Input array 2 * @return A new array with the element-wise sum * */ public static double[] sum(long[] array1, long[] array2) { double[] out = new double[array1.length]; for (int i = 0; i < out.length; i++) out[i] = array1[i] + array2[i]; return out; } }