if ( str.isEmpty() ) return 0; else if ( str.charAt(0) == 'X' ) return 1 + xLength( str.substring(1) ); else return 0 + xLength( str.substring(1) );
Consider the reverse of a string:
The reverse of the string "" is "" The reverse of the string "X" is "X" The reverse of the string "Xabc" is "cbaX"
Say that you have a string that looks like this (the character 'X' could be any character):
To reverse a string, put the first character at the end of the reversed tail:
How do you reverse the tail?