Question: Consider the following recursive method. public static String doSomething(String str) { if (str.length() < 1) { return ; } else { return str.substring(0, 1) +
Consider the following recursive method.
public static String doSomething(String str)
{
if (str.length() < 1)
{
return "";
}
else
{
return str.substring(0, 1) + doSomething(str.substring(1));
}
}
Which of the following best describes the result of the call doSomething(myString) ?
A. The method call returns a String containing the contents of myString unchanged.
B. The method call returns a String containing the contents of myString with the order of the characters reversed from their order in myString.
C. The method call returns a String containing all but the first character of myString.
D. The method call returns a String containing only the first and second characters of myString.
E. The method call returns a String containing only the first and last characters of myString.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
