• Post Reply Bookmark Topic Watch Topic
  • New Topic

Else if part is not getting executed  RSS feed

 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



the input is Tyrannosaurus, 4, 2.2, 3, 9.9, 5, 1.1, Tyrannosaurus, Rex

Can anybody explain to me why this doesn't execute the else if part because its supposed to or are my curly braces in the wrong places? when i run it, it outputs the farewell part. any tips?? 
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't compare String instances with the == operator. You must use firstWord.equals(secondWord).
The == operator will determine whether the String variables refer to the same String instance, not whether the contents of two instances are the same.
 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:Don't compare String instances with the == operator. You must use firstWord.equals(secondWord).
The == operator will determine whether the String variables refer to the same String instance, not whether the contents of two instances are the same.

Thanks! i forgot about that 
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!