Recursive String Method Trace
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
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | ethan | 2 | 2 | 1m 04s | 136 |
| #2 | songqiuhui2012 | 0 | 1 | 0m 25s | -35 |
| #3 | singhris000 | 0 | 2 | 2m 35s | -175 |
| #4 | upadhgau000 | 0 | 1 | 2m 52s | -182 |
| #5 | suhanakochhar006 | 1 | 3 | 5m 24s | -244 |
| #6 | psak12 | 1 | 2 | 8m 22s | -412 |
| #7 | richa.tuli | 2 | 3 | 13m 05s | -595 |
APFIVE