Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to fix error on Queue when using it with a Stack for a Palindrome?

  1. #1
    Junior Member SarahDoesIt's Avatar
    Join Date
    Nov 2012
    Posts
    3
    My Mood
    Angelic
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation How to fix error on Queue when using it with a Stack for a Palindrome?

    I receive an error when trying to compile my Java code for a palindrome.

    This is my error, and I don't understand why I am receiving this error. Can someone please help me? Thank you.


    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The type Queue is not generic; it cannot be parameterized with arguments <Character>

    at palindrome5.main(palindrome5.java:13)


    This is my code:
    import java.util.*;
     
    public class Palindrome2
    {
    public static void main(String [] args)
    {
    String input = args[0];
    // For ignoring case
    String inputString = input.toLowerCase();
    // Create stack
    Stack<Character> stack = new Stack<Character>();
    // Create queue
    Queue<Character> queue = new LinkedList<Character>();
     
     
    // Add input string to stack and queue
    for ( int i = 0 ; i < inputString.length() ; i++ )
    {
    stack.push(inputString.charAt(i));
    queue.add(inputString.charAt(i));
    }
     
    boolean palindrome = true;
     
    while ( !stack.isEmpty() && palindrome == true ) {
    if ( Character.isLetter(stack.peek()) && Character.isLetter(queue.peek()) )
    {
    // Check for comparison
    if ( stack.pop().equals( queue.remove() ) == false ) {
    palindrome = false;
    }
     
    }
    else
    {
    if ( !Character.isLetter(stack.peek()))
    stack.pop();
    if ( !Character.isLetter(queue.peek()))
    queue.remove();
     
    }
     
    }
    // Output
    System.out.println("Text: " + input );
    System.out.println("Palindrome: " + palindrome);
    }
    }


  2. #2
    Junior Member SarahDoesIt's Avatar
    Join Date
    Nov 2012
    Posts
    3
    My Mood
    Angelic
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to fix error on Queue when using it with a Stack for a Palindrome?

    NM. I found the problem I was having. Thanks.

Similar Threads

  1. [SOLVED] Double key Caesar Cipher (USING A STACK AND A QUEUE TO SHIFT LETTERS OF A STRING)
    By Medo Almasry in forum What's Wrong With My Code?
    Replies: 16
    Last Post: November 19th, 2011, 04:18 PM
  2. Replies: 0
    Last Post: November 6th, 2011, 03:55 PM
  3. stack Palindrome , java
    By Faha in forum Object Oriented Programming
    Replies: 1
    Last Post: May 3rd, 2011, 04:20 PM
  4. Implementing a queue or stack using a heap
    By tla280 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 1st, 2010, 12:29 AM
  5. Error of "cannot access InToPost" in 3 and 5 code
    By jaysoncutie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 25th, 2009, 09:12 AM