I am given an array of name 'array[]
' with an unknown amount of elements. I am asked to return the sum of all of the values in the array, and I tried to write a for
loop covering all of the values in the array and adding them together. I think that I am overthinking this, and I should be able to do this in one command but I can't remember.
Here is what I am given:
int arraySum(int[] array)
I tried:
for(int i = 0; i <= array.length; i++){
int sum = array[i];
}
return sum;