go to previous page   go to home page   go to next page

Answer:

if ( str.isEmpty() ) 
  return 0;
else if ( str.charAt(0) == 'X' )
  return 1 + xLength( str.substring(1) );
else
  return 0 + xLength( str.substring(1) );

String Reversal

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):

Head character followed by a tail

To reverse a string, put the first character at the end of the reversed tail:

Reversed String

QUESTION 11:

How do you reverse the tail?


go to previous page   go to home page   go to next page