Here you can find the source of sum(short[] ary)
Parameter | Description |
---|---|
ary | the array of integers to sum |
public static final int sum(short[] ary)
//package com.java2s; //License from project: Open Source License public class Main { /** Sum of an array/*from w ww .jav a 2s . c om*/ * @param ary the array of integers to sum * @return the sum of all of the elements in the specified array */ public static final int sum(byte[] ary) { return sum(ary, 0, ary.length); } /** Sum of the subset of an array * @param ary the array of bytes to sum * @param offset the offset into the array at which to start summing values * @param length the number of elements to sum from the array starting * at {@code offset} * @return the sum of the specified array subset */ public static final int sum(byte[] ary, int offset, int length) { int offLen = offset + length; int sum = (byte) 0; for (int i = offset; i < offLen; i++) { sum += ary[i]; } return sum; } /** Sum of an array * @param ary the array of integers to sum * @return the sum of all of the elements in the specified array */ public static final int sum(short[] ary) { return sum(ary, 0, ary.length); } /** Sum of the subset of an array * @param ary the array of shorts to sum * @param offset the offset into the array at which to start summing values * @param length the number of elements to sum from the array starting * at {@code offset} * @return the sum of the specified array subset */ public static final int sum(short[] ary, int offset, int length) { int offLen = offset + length; int sum = (short) 0; for (int i = offset; i < offLen; i++) { sum += ary[i]; } return sum; } /** Sum of an array * @param ary the array of integers to sum * @return the sum of all of the elements in the specified array */ public static final int sum(char[] ary) { return sum(ary, 0, ary.length); } /** Sum of the subset of an array * @param ary the array of chars to sum * @param offset the offset into the array at which to start summing values * @param length the number of elements to sum from the array starting * at {@code offset} * @return the sum of the specified array subset */ public static final int sum(char[] ary, int offset, int length) { int offLen = offset + length; int sum = (char) 0; for (int i = offset; i < offLen; i++) { sum += ary[i]; } return sum; } /** Sum of an array * @param ary the array of integers to sum * @return the sum of all of the elements in the specified array */ public static final int sum(int[] ary) { return sum(ary, 0, ary.length); } /** Sum of the subset of an array * @param ary the array of ints to sum * @param offset the offset into the array at which to start summing values * @param length the number of elements to sum from the array starting * at {@code offset} * @return the sum of the specified array subset */ public static final int sum(int[] ary, int offset, int length) { int offLen = offset + length; int sum = 0; for (int i = offset; i < offLen; i++) { sum += ary[i]; } return sum; } /** Sum of an array * @param ary the array of integers to sum * @return the sum of all of the elements in the specified array */ public static final long sum(long[] ary) { return sum(ary, 0, ary.length); } /** Sum of the subset of an array * @param ary the array of longs to sum * @param offset the offset into the array at which to start summing values * @param length the number of elements to sum from the array starting * at {@code offset} * @return the sum of the specified array subset */ public static final long sum(long[] ary, int offset, int length) { int offLen = offset + length; long sum = 0L; for (int i = offset; i < offLen; i++) { sum += ary[i]; } return sum; } /** Sum of an array * @param ary the array of integers to sum * @return the sum of all of the elements in the specified array */ public static final float sum(float[] ary) { return sum(ary, 0, ary.length); } /** Sum of the subset of an array * @param ary the array of floats to sum * @param offset the offset into the array at which to start summing values * @param length the number of elements to sum from the array starting * at {@code offset} * @return the sum of the specified array subset */ public static final float sum(float[] ary, int offset, int length) { int offLen = offset + length; float sum = 0f; for (int i = offset; i < offLen; i++) { sum += ary[i]; } return sum; } /** Sum of an array * @param ary the array of integers to sum * @return the sum of all of the elements in the specified array */ public static final double sum(double[] ary) { return sum(ary, 0, ary.length); } /** Sum of the subset of an array * @param ary the array of doubles to sum * @param offset the offset into the array at which to start summing values * @param length the number of elements to sum from the array starting * at {@code offset} * @return the sum of the specified array subset */ public static final double sum(double[] ary, int offset, int length) { int offLen = offset + length; double sum = 0; for (int i = offset; i < offLen; i++) { sum += ary[i]; } return sum; } }