How to find the sum of all the numbers in an array in java?
Answers
Answered by
0
In java-8 you can use streams:
int[] a = {10,20,30,40,50};
int sum = IntStream.of(a).sum();
System.out.println("The sum is " + sum);
Output:
The sum is 150.
It's in the package java.
util.stream
Similar questions