I need to write a java method sumAll() which takes any number of integers and returns their sum.
sumAll()
sumAll(1,2,3) returns 6 sumAll() returns 0 sum
You could do, assuming you have an array with value and array length: arrayVal[i], arrayLength:
arrayVal[i]
arrayLength
int sum = 0; for (int i = 0; i < arrayLength; i++) { sum += arrayVal[i]; } System.out.println("the sum is" + sum);
I hope this helps.