Write the definition of a method named sumArray that has one parameter, an array of int s. The method returns the sum of the elements of the array as an int.

LANGUAGE: JAVA

CHALLENGE:

Write the definition of a method named sumArray that has one parameter, an array of int s. The method returns the sum of the elements of the array as an int.

SOLUTION:

int sumArray(int a[]) {
int i,total = 0;
for(i = 0; i < a.length; i++)
total += a[i];
return total;
}