Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Syntax or logic error?

 
Ian Mcloud
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
== operator checks for references. You should have used equals() method for string comparison
 
Gihan Pandigamage
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use equals() method to do String comparison.
for further details read this

http://www.leepoint.net/notes-java/data/strings/12stringcomparison.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic