Kotlinlearncs.online LogoJava
Return to List

Solve: Sum Array Odds

Created By: Rohith Sanjay
/ Version: 2024.9.1

Write a method sumArrayOdds that takes in one argument: an IntArray? called input. This method will return the "Odd Sum", as described below. The "Odd Sum" is the sum of the odd elements with odd indices in the array. So for example, if input = [3, 3, 3, 4, 4], then sumArrayOdds will return 3, because the second element (index 1) is the only element with an odd value (3) and odd index (1), so it is the only element in the sum. If input = [1, 1, 1, 1, 1], then sumArrayOdds will return 2. If input is null or empty, then return 0. Remember that an array is zero-indexed, so the first element has index 0, the second element has index 1, and so on.

Related Lessons

Stuck? You may find these lessons helpful:

Report a Problem

Attribution must link to this page: https://www.learncs.online/solve/kotlin/sum-array-odds/[email protected]