public static String mystery (String s) { char []temp = new char[1]; if (s.equal
ID: 3898313 • Letter: P
Question
public static String mystery (String s)
{
char []temp = new char[1];
if (s.equals("")) return"";
if("aeiouAEIOU".indexOf(s.charAt(0)) != -1)
{
temp[0]=s.charAt(0);
return new String(temp) + mystery(s.substring(1));
}
else return "" + mystery(s.substring(1));
}
a) show all the call to the function and what each one returns to its predecessor?
String result = mystery ("Omar");
Call#
1. mystery("Omar") returns ____ to result
2. mystery("___") returns _____ to Call ____
3. mystery ("__") returns ____ to Call #2.
4. mystery ("__") returns ____ to Call ___
5. mystery ("") returns "" to Call#4
b) Describe what the mystery method accomplishes
Explanation / Answer
Answer a) The value of result is "Oa"
The calls and values returned are
1. mystery("Omar") returns "Oa" to result
2. mystery("mar") returns "a" to Call #1
3. mystery ("ar") returns "a" to Call #2.
4. mystery ("r") returns "" to Call #3
5. mystery ("") returns "" to Call#4
===============
Answer to b)
mystery function retains only vowels and removes all other characters from the input string s
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.