Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice TestPractice Test
About Exam
easy

Recursive Linear Search

Mark
< Prev
Next >

Consider the following recursive findPosition method. What is printed as a result of executing the code segment in the main method comment?

public int findPosition(int nums[], int key, int currentIndex) {
    if(currentIndex >= nums.length)
       return -1;
    if(nums[currentIndex] == key)
       return currentIndex;
    return findPosition(nums, key, currentIndex + 1);
}

// In main:
// int[] players = {3, 7, 9, 5, 9};
// System.out.println(findPosition(players, 9, 0));
A

4

B

2

C

-1

D

0

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|