### 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; }

int sumArray(int a[])

{

int i,total = 0;

for(i = 0; i < a.length; i++)

total += a[i];

return total;

}

public int sumArray(int[] s)

{

int sum = 0;

for(int i = 0; i < s.length; i++)

{

sum += s[i];

}

return sum;

}

Try this:

public int sumArray(int[] s) {

int sum = 0;

for(int i : s)

sum += i;

return sum;

}

try this:

public boolean isReverse (int[] a, int[] b) {

int k;

for (k = 0; k < a.length && a[k] == b[a.length-1-k]; k++);

return k == a.length;

}