It's not a secret anymore!
The moose likes Beginning Java and the fly likes Syntax or logic error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Syntax or logic error?" Watch "Syntax or logic error?" New topic

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

Joined: Jan 03, 2004
Posts: 6109

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: 32

== operator checks for references. You should have used equals() method for string comparison
Gihan Pandigamage
Ranch Hand

Joined: Aug 23, 2009
Posts: 60
Use equals() method to do String comparison.
for further details read this
I agree. Here's the link:
subject: Syntax or logic error?
jQuery in Action, 3rd edition