Question: Hand tracing the code, this is java code. public int mystery(String str) { if (str.length() == 0) return 0; if (str.charAt(0) == 'x') return 1
Hand tracing the code, this is java code.
public int mystery(String str) {
if (str.length() == 0)
return 0;
if (str.charAt(0) == 'x')
return 1 + mystery(str.substring(1));
return mystery(str.substring(1));
}
mystery(xaxbxcx)
public int foo(String str) {
if (str.length() < 2)
return 0;
if (str.substring(0,2).equals("hi"))
return 1 + foo(str.substring(1));
else
return foo(str.substring(1));
}
}
foo(xhixhy)
public static String deez(String str) {
if ((null == str) || (str.length() <= 1)) {
return str;
}
return deez(str.substring(1)) + str.charAt(0);
}
deez(track)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
