Click to See Complete Forum and Search --> : Sum of Array values


eyeoforion
04-12-2005, 01:00 AM
Ok I have an array with lets say 10 numbers in it. How would I go about getting the program to calculate the sum of these numbers. In other words getting the program to add each number in the array together??

Cheers, Orion

buntine
04-12-2005, 01:05 AM
Just write a little function.

public int sumArray(int [] arr)
{
int sum = 0;
for (int i=0; i<arr.length; i++)
sum += arr[i];
return sum;
}

Regards.