Recursive String Length Method
The stringLength method below is intended to recursively calculate the length of a string.
public static int stringLength(String s) {
if(s.equals("")) {
return 0;
}
/* missing line */
}
Which statement, if it replaces /* missing line */, will ensure that the method works as intended?
A
return stringLength(s.substring(1));
B
return 1 * stringLength(s.substring(1));
C
return 1 - stringLength(s.substring(1));
D
return 1 + stringLength(s.substring(1));
Question Leaderboard
Not enough data yet to show leaderboard.
