I'm working on a Palindrome program. For some reason, my compare method always return zero. "c" should suppose to increment 1 when both letter are the same, but my method would not increment 1 when the letter are the same for some reason. I'm not sure where is the problem.
This is the method I create to compare:
public int compare(String words)
{
ArrayQueue<Character> q = new ArrayQueue<Character>();
Stack<Character> s = new Stack<Character>();
int c=0;
for(int i =0; words.length()<i; i++)
{
q.enqueue(words.charAt(i));
s.push(words.charAt(i));
}
while(!s.isEmpty())
{
if (s.pop().equals( q.dequeue() ) )
c++;
}
if(c==0)
return 0;
else
return 1;
}
it is always return 0, I have been think and search for error for over two hours. I still don't get why it would always return 0;