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
APFIVE