I have been asked to create to check if a word is palindrome or not. But I am facing some problems. After the code you can see the messages that I received from the compiler.
import java.util.*;
public class Palindrome {
public static void main(String[] args)
{
[B]Stack<String> stack = new ArrayStack<String>();
Queue<String> queue = new ArrayQueue<String>();[/B]
int x = 0;
try
{
String word = "kayak";
for(int i = 0; i < word.length(); i++)
{
Character temp = word.charAt(i);
[B]stack.push(temp);
queue.offer(temp);[/B]
}
while(!queue.isEmpty())
{
if(queue.poll() != stack.pop())
{
System.out.println("Not a palindrome");
break;
}
else
{
++x;
continue;
}
}
if(x == word.length())
{
System.out.println("It is a palindrome!");
}
}
catch(EmptyStackException e)
{
System.out.println("No characters in the stack");
}
}
}
1.ArrayStack cannot be resolved to a type.
2.ArrayQueue cannot be resolved to a type.
3.The method push(String) in the type Stack<String> is not applicable for the arguments (Character).
4.The method offer(String) in the type Queue<String> is not applicable for the arguments (Character).
I appreciate any help from you guys.