how to sum different integers in an array in java code example
Example 1: how to add up all numbers in an array
var numbers = [10, 20, 30, 40]
var sum = 0;
for (var i = 0; i < numbers.length; i++) { sum += numbers[i]}
Example 2: arrays.sum
int sum = Arrays.stream("1 2 3 4".split("\\s+")).mapToInt(Integer::parseInt).sum();