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 String Length Method

Mark
< Prev
Next >

The stringLength method below is intended to recursively calculate the length of a string.

public static int stringLength(String s) {
    if(s.equals("")) {
        return 0;
    }
    /* missing line */
}

Which statement, if it replaces /* missing line */, will ensure that the method works as intended?

A

return stringLength(s.substring(1));

B

return 1 * stringLength(s.substring(1));

C

return 1 - stringLength(s.substring(1));

D

return 1 + stringLength(s.substring(1));

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|