🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #551

Re: [FAQ] Wierd system.out.println

#551
From: Steve Chapel
Date: Wed, 23 Aug 2000 00:00
47 lines
2481 bytes
"Nicholas Routledge" <n.routledge@bigpond.com> wrote in message
news:s5Oo5.36404$c5.101625@newsfeeds.bigpond.com...
> Hi all,
>
> I'm having this extremely frustrating problem that i can't see to fix.
> I have a method called processRequest and when called, returns a string.
> After processRequest is called, the string that is returned is assigned to
a
> variable called status.
> this is what i have next,
>
> if (status.equals("Confirm")) {
>     ...
>     System.out.println("Confirm (Y/N): ");
>     char c = (char) br.read();
>     ...
> }
>
> else if (status.equals("Alternate")) {
>     ...
>     System.out.println("Confirm (Y/N): ");
>     char c = (char) br.read();
>     ...
> }
> .
> .
>
> Now the problem is, the System.out.println statements in each conditional
> branch are executed TWICE for some reason.  They should only be executed
> once because the statements are not nested inside a loop.  Also, i have no
> recursion anywhere in the program.
>
> For example, if the first branch is taken, it prints out,
> "Confirm (Y/N): "
> "Confirm (Y/N): "
>
> Its extremely wierd but i was wondering whether anyone had any suggestions
> or whether anyone had seen this problem before?
> I can't explain it.


The read() method call returns the next *byte* of data from the input
stream. You probably want to read the next *line* from the stream; Q7.2 in
the Java Programmers FAQ shows you how to do that.
--
Java Programmers FAQ:  http://www.afu.com/javafaq.html
           Java Docs:  http://java.sun.com/docs/
Technical Details
Message-ID: <8o0mds$c0q$1@news.tribune.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <s5Oo5.36404$c5.101625@newsfeeds.bigpond.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113ae9,23055c9aac63ea4a
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10a146,23055c9aac63ea4a
X-Google-Attributes: gid10a146,public
X-Google-Thread: 10d6db,23055c9aac63ea4a
X-Google-Attributes: gid10d6db,public
From: "Steve Chapel" <schapel@breakthr.com>
Subject: Re: [FAQ] Wierd system.out.println
Date: 2000/08/23
Message-ID: <8o0mds$c0q$1@news.tribune.com>
X-Deja-AN: 661550722
References: <s5Oo5.36404$c5.101625@newsfeeds.bigpond.com>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-Complaints-To: llynch@tribune.com
X-Trace: news.tribune.com 967040252 12314 163.192.185.93 (23 Aug 2000 14:17:32 GMT)
Organization: Tribune Information Networks 
X-MSMail-Priority: Normal
NNTP-Posting-Date: 23 Aug 2000 14:17:32 GMT
Newsgroups: aus.computers.java,comp.lang.java.help,comp.lang.java.programmer