I need to write a java method sumAll()
which takes any number of integers and returns their sum.
sumAll(1,2,3) returns 6
sumAll() returns 0
sumAll(20) returns 20
I don't know how to do this.
I need to write a java method sumAll()
which takes any number of integers and returns their sum.
sumAll(1,2,3) returns 6
sumAll() returns 0
sumAll(20) returns 20
I don't know how to do this.
You need:
Then call the method and give it as many int values as you need:
You could do, assuming you have an array with value and array length:
arrayVal[i]
,arrayLength
:I hope this helps.
If your using Java8 you can use the IntStream:
Just 1 line of code which will sum the array.