Write here if you have problems with your Java source code
Moderator: Board moderators
- Learning poster
- Posts: 69
- Joined: Tue Jan 30, 2007 12:51 am
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);
while ((mole1 = br.readLine()) != null && mole1 != "Q")
but it doesn't works
- Posts: 1244
- Joined: Mon Feb 28, 2005 4:51 am
- Location: Zürich, Switzerland
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.