Here you can find the source of sum(int[] a)
Parameter | Description |
---|---|
a | a parameter |
public static int sum(int[] a)
//package com.java2s; /******************************************************************************* * OscaR is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 2.1 of the License, or * (at your option) any later version./*from w ww .j a v a 2 s . c o m*/ * * OscaR 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with OscaR. * If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html ******************************************************************************/ public class Main { /** * * @param a * @return the sum of the values in a */ public static int sum(int[] a) { int v = 0; for (int i : a) { v += i; } return v; } /** * * @param a * @return the sum of the values in a */ public static double sum(double[] a) { double v = 0; for (double i : a) { v += i; } return v; } /** * * @param a * @return the sum of the values in a */ public static int sum(int[][] a) { int s = 0; for (int i = 0; i < a.length; i++) { s += sum(a[i]); } return s; } }