I need a bit of help making a palindrome tester...
For those of you unfamiliar w/ palindromes its a word like so:
Raceacr
spelled the same way forward and backward...
so here is my code:
import java.util.*;
public class Palindrome
{
public static void main(String[] args)
{
String deLimiters = ";:'<>,./?-+!@#$%^&*() ";
Stack<String> stack = new Stack<String>();
Scanner reader = new Scanner(System.in);
while(true)
{
String palindrome = "";
String backwards = "";
System.out.println("Please enter a palindrome (Type n to quit): ");
String str = reader.nextLine();
if(str.equalsIgnoreCase("n"))
{
System.exit(0);
}
StringTokenizer tokens = new StringTokenizer(str, deLimiters);
StringTokenizer tokens2 = new StringTokenizer(palindrome, deLimiters);
while(tokens.hasMoreTokens())
{
palindrome += tokens.nextToken();
}
for(int i = 0; i < palindrome.length(); i++)
{
stack.add(palindrome.substring(i, i +1));
}
while(! stack.empty())
{
backwards += stack.pop();
}
if(palindrome.equalsIgnoreCase(backwards))
{
System.out.println("Your phrase: " + palindrome + " is a Palindrome");
}
else
{
System.out.println("Your phrase: " + palindrome + " is not a Palindrome");
}
}
}
}
i need some help just making it work...