| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
Share
About Exam
medium
Recursive Array Processing
< Prev
Next >

What is the sum of all odd numbers printed by the program?

public class SumOdds {
    public static int sumOdds(int[] arr, int index) {
         if(index == arr.length) return 0;
         if(arr[index] % 2 != 0)
             return arr[index] + sumOdds(arr, index + 1);
         else
             return sumOdds(arr, index + 1);
    }
    public static void main(String[] args) {
         int[] numbers = {2, 3, 5, 6, 7};
         System.out.println(sumOdds(numbers, 0));
    }
}
A

12

B

15

C

10

D

9

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy