| Author |
Syntax or logic error?
|
Ian Mcloud
Ranch Hand
Joined: Oct 04, 2012
Posts: 76
|
|
So can anyone tell me why only the second option will display regardless if the user chooses option 1 or 2? If the use types "yes," the .txt should be read into the program and printed in the console. If "no" is typed in, the myMenu() method should display the System.out line, which it does.
|
 |
Ian Mcloud
Ranch Hand
Joined: Oct 04, 2012
Posts: 76
|
|
|
I've managed to get either one or the other to work, but never both at the same time. Though I did have it where the both options would print simultaneously, though that's not what I want, hence the use of options.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5807
|
|
|
Use equals(), not ==, to compare objects' states (such as Strings' contents). The == operator on reference types tells you whether the references have the same values, that is, whether both point to the same object or both are null.
|
 |
Saket Kumar Sinha
Ranch Hand
Joined: Aug 04, 2011
Posts: 31
|
|
== operator checks for references. You should have used equals() method for string comparison
|
 |
Gihan Pandigamage
Ranch Hand
Joined: Aug 23, 2009
Posts: 57
|
|
Use equals() method to do String comparison.
for further details read this
http://www.leepoint.net/notes-java/data/strings/12stringcomparison.html
|
 |
 |
|
|
subject: Syntax or logic error?
|
|
|