X327: sumAlternates

Given an array of integers, return the sum of every other value in the array, starting with the first element. For example, if the array contains the values {1, 2, 3, 4, 5, 6}, the method should return the sum of 1, 3, and 5, which is 9.

Examples:

sumAlternates({1, 2, 3, 4, 5, 6}) -> 9
sumAlternates({10, 30, 100, 60}) -> 110

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.