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

Pages: 1-

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: >>1 2011-04-04 0:55

I'll just try  to store the EOF into a char and catch it later.
Nevermind that, after attempting to store it in a char to cause an Exception I discovered that the ^Z was being COMPLETELY IGNORED.  What the HELL is going on?

Name: Anonymous 2011-04-04 1:10

>>2
Java
There's your problem.

Name: Anonymous 2011-04-04 5:35

>>2
[spoiler][quote]implying windoze[/quote][spoiler]

EOF is not a character. ^Z is not EOF.

You need to follow the ^Z with a newline to SEND EOF (try [code]copy con nul[spoiler]^M[/spoiler][/code] if you don't believe me).

Name: Anonymous 2011-04-04 5:41

>>4
[b][i]EXPERT BBCODE FAILURE[/i][/b]

>>2
[quote]implying windoze[/quote]

EOF is not a character. ^Z is not EOF.

You need to follow the ^Z with a newline to [b][i]SEND EOF[/i][/b] (try copy con nul[spoiler]^M[/spoiler] if you don't believe me).

Name: Anonymous 2011-04-04 5:43

>>4,5
Trying too hard.

Name: Anonymous 2011-04-04 5:44

>>6
fuck off, faggot

Name: Anonymous 2011-04-04 5:47

>>4,5
EXPERT BBCODE FAILURE

>>2
[quote]implying windoze[/quote]
EOF is not a character. ^Z is not EOF.

You need to follow the ^Z with a newline to SEND EOF (try copy con nul^M if you don't believe me).

Name: Anonymous 2011-04-04 5:49

>>4,5,6,8

Indeed. Fuck Shitchan, I am going to bed.

Name: Anonymous 2011-04-04 12:55

>>9

>>4,5
[b][u][i][o]EXPERT BBCODE FAILURE[/o][/i][/u][/b]

>>2
[rem][/rem] [spoiler]implying wind[spoiler]oze[/spoiler][/spoiler]
EOF is not a character. [code]^Z[/code] is not EOF.

You need to follow the [code]^Z[/code] with a newline to [b][u][i][o]SEND EOF[/o][/i][/u][/b] (try [m]copy con nul[spoiler]^M[/spoiler][/m] if you don't believe me).

Thank me later.

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