Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scanners put into if statements

 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was curious on why when i try to use this method in my driver it wont accept what i type in as either the If or the Else If.
Am I programing something wrong? Because I've been working on this for hours and cant get it.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you compare Strings with == operator? You should use equals instead.

This is the preferred way to test for equality, which prevents NullPointerException to be thrown.

Edit: Those long lines in your code really spoil the layout of the page. You could edit your original post and make those lines shorter.
 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked wonderfully. Thank you so much.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.

Do you understand the difference between == operator and equals() method? Make sure you understand why your code didn't work.
 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, not fully. Could you explain it for?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Hammersmith wrote:No, not fully. Could you explain it for?

I could, but the question has been asked quite a times here so a little search will probably give you a satisfactory answer (link).
 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much, again.
 
Campbell Ritchie
Sheriff
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another link about ==
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic