Java Input Read...

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Java Input Read...

Post by x140l31 » Sat May 31, 2008 11:49 pm

Hi,

I'm a newby in Java, I need some help for the inputs like...

".. a line with two integers 0 0 indicate the end of data."

two integers... or a string...

How can I read for this problems?

I try this:

Code: Select all

InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);

String mole1;
while ((mole1 = br.readLine()) != null && mole1 != "Q")
but it doesn't works :(

thanks!!!

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: Java Input Read...

Post by mf » Sun Jun 01, 2008 10:51 am

Operators == and != compare objects' addresses.
Two strings coming from different places (such as string from readLine method, and hard-coded "Q" in your class) are never going to be equal according to the == operator, because they're represented by different objects, even if their contents are the same.

You should use String.equals() method to compare strings instead.

Post Reply

Return to “Java”