Java examples for Collection Framework:Array Algorithm
Returns the sum of the elements of the array.
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { double[] v = new double[] { 34.45, 35.45, 36.67, 37.78, 37.0000, 37.1234, 67.2344, 68.34534, 69.87700 }; System.out.println(mass(v)); }/* w ww .ja v a2 s.c o m*/ /** * Returns the sum of the elements of the array. */ public static double mass(double[] v) { double somme = 0.0; for (int k = 0; k < v.length; k++) { somme += v[k]; } return (somme); } /** * Returns the sum of the elements of the array. */ public static int mass(int[] v) { int somme = 0; for (int k = 0; k < v.length; k++) { somme += v[k]; } return (somme); } }