Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fucking Java

Name: Anonymous 2011-04-04 0:19

        while (input.hasNext())
        {   
            char cha = input.next().charAt(0);
                   
            if (Character.isLetter(cha))
            {
                CharElement nextLetter = new CharElement(Character.toUpperCase(cha));
                testStack.push(nextLetter);
                testQueue.addQueue(nextLetter);
            }
           
            if (cha == '\n')
            {
                while (!testQueue.isEmptyQueue())
                {
                        System.out.println(testStack.top().toString()+ testQueue.front().toString());
                    if (((CharElement)testStack.top()).getCha() == ((CharElement)testQueue.front()).getCha())
                    {
                        testStack.pop();
                        testQueue.deleteQueue();
                        if (testQueue.isEmptyQueue())
                            System.out.println("Palindrome");
                    }
                   
                    else
                    {
                        System.out.println("Not palindrome");
                        testQueue.initializeQueue();
                        testStack.initializeStack();
                    }
                }       
                System.out.println("Next!");
            }
        }
    }

Basically, I'm supposed to collect lines of input from the user, take only the letters from the lines, put them into a queue and stack, then advance and pop the two to check if the line is a palindrome. input is a Scanner attached to System.in.  I changed the delimiter to "" so I could scan through the input character-by-character.  testStack and testQueue are just linked lists made up of CharElements.  Everything almost works fine.

My problem is that the while loop is supposed to terminate when it reaches an EOF (^Z).  For some reason, the loop terminates when a line starts with ^Z but not at the middle or end.  I can't for the life of me figure out why this is.

Worst come to worst, I'll just try to store the EOF into a char and catch it later.  But I'd like to avoid that, if at all possible.  Can you help me avoid it, /prog/?

Name: Anonymous 2011-04-04 5:49

>>4,5,6,8

Indeed. Fuck Shitchan, I am going to bed.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List