← Unit 4 · all exercises
Saved in this browser only

Add up an array

Return the total of every number in the array. An empty array totals zero.

int sum(int[] values)

Solution.java
Loading editor…
Results

Examples

  • Solution.sum(new int[]{1, 2, 3}) → 6
  • Solution.sum(new int[]{}) → 0

There are also 3 hidden tests you can't see. Solve the problem, not the examples.