Java Array Sum sum(int[] numbers)

Here you can find the source of sum(int[] numbers)

Description

sum

License

Open Source License

Declaration

public static int sum(int[] numbers) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int sum(int[] numbers) {
        int s = 0;
        for (int number : numbers)
            s += number;/*from w  w w  .  j a va 2  s. c o  m*/
        return s;
    }

    public static int sum(int[] numbers, int limit) {
        int s = 0;
        for (int i = 0; i < numbers.length && i < limit; i++)
            s += numbers[i];
        return s;
    }

    public static float sum(float[] numbers) {
        float s = 0;
        for (float number : numbers)
            s += number;
        return s;
    }

    public static float sum(float[] numbers, int limit) {
        float s = 0;
        for (int i = 0; i < numbers.length && i < limit; i++)
            s += numbers[i];
        return s;
    }
}

Related

  1. sum(int[] array)
  2. sum(int[] array)
  3. sum(int[] intArray)
  4. sum(int[] ints)
  5. sum(int[] list)
  6. sum(int[] source)
  7. sum(int[] values)
  8. sum(int[] values)
  9. sum(int[] values, int begin, int end)