| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice Test
Share
medium Solved by 11 students
Recursive String Method Trace
< Prev
Next >

What is printed as a result of the call whatsItDo(“BATCH”)?
Consider the following recursive method:

public static void whatsItDo(String str)
{
    int len = str.length();
    if (len > 1)
    {
        String temp = str.substring(0, len - 1);
        whatsItDo(temp);
        System.out.println(temp);
    }
}

What is printed as a result of the call whatsItDo("BATCH")?

A

BATCH
BATC
BAT
BA
B
BA
BAT
BATC
BATCH

B

BATCH
BATC
BAT
BA

C

BATC
BAT
BA
B

D

B
BA
BAT
BATC

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1ethan22 1m 04s 136
#2songqiuhui201201 0m 25s -35
#3singhris00002 2m 35s -175
#4upadhgau00001 2m 52s -182
#5suhanakochhar00613 5m 24s -244
#6psak1212 8m 22s -412
#7richa.tuli23 13m 05s -595
APFIVE © 2020.
Email: [email protected]|Privacy Policy