question archive Write boolean method that uses recursion to determine whether a String argument is a palindrome
Subject:Computer SciencePrice:2.86 Bought9
Write boolean method that uses recursion to determine whether a String argument is a palindrome. The method should return true if the argument reads the same forward and backward. Demonstrate the method in a program
public static boolean is_palindrome(String input)
{
Queue<Character> q = new LinkedList<Character>( );
Stack<Character> s = new Stack<Character>( );
Character letter; // One character from the input string
int mismatches = 0; // Number of spots that mismatched
int i; // Index for the input string
for (i = 0; i < input.length( ); i++)
{
letter = input.charAt(i);
if (Character.isLetter(letter))
{
q.add(letter);
s.push(letter);
}
}
while (!q.isEmpty( ))
{
if (q.remove( ) != s.pop( ))
mismatches++;
}
// If there were no mismatches, then the string was a palindrome.
return (mismatches == 0);
}
}