← Unit 4 · all exercises
Saved in this browser only

Every other one

Return the total of the items at positions 0, 2, 4 and so on. It is the position that must be even, not the value.

int sumEvenIndexes(int[] values)

Solution.java
Loading editor…
Results

Examples

  • Solution.sumEvenIndexes(new int[]{1, 2, 3, 4}) → 4
  • Solution.sumEvenIndexes(new int[]{5}) → 5

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