Computer Science, asked by kumarvivek7690, 1 year ago

How to find the sum of all the numbers in an array in java?

Answers

Answered by Saimrock78
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