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
If your using Java8 you can use the IntStream:
int[] listOfNumbers = {5,4,13,7,7,8,9,10,5,92,11,3,4,2,1}; System.out.println(IntStream.of(listOfNumbers).sum());
Results: 181
Just 1 line of code which will sum the array.