• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Else if part is not getting executed

 
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??  
 
Bartender
Posts: 732
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic