• Post Reply Bookmark Topic Watch Topic
  • New Topic

If else Problem  RSS feed

 
Tommy Green
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello forum, could someone please kindly tell me whats wrong with my if else code there? It's not running correctly, it skips the "if" and "else if", and it directly jumps to "else" no matter what.

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What's wrong is that you are using == to compare strings. Use equals() instead:

The == operator, when used on objects, does not check if the content of the objects is the same - it checks if both operands (on the left and right side of the ==) refer to the exact same object. Even if you have two String objects that have the same content, the result will be false because they are two distinct String objects.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:Oh, and you're usually better off using spaces for indentation, rather than TABs.

That was actually the topic of a lengthy debate here in Meaningless Drivel not too long ago...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!