| Author |
Scanners put into if statements
|
Andy Hammersmith
Greenhorn
Joined: Sep 30, 2012
Posts: 13
|
|
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
Joined: Jun 19, 2010
Posts: 800
|
|
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.
|
The quieter you are, the more you are able to hear.
|
 |
Andy Hammersmith
Greenhorn
Joined: Sep 30, 2012
Posts: 13
|
|
|
That worked wonderfully. Thank you so much.
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 800
|
|
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
Joined: Sep 30, 2012
Posts: 13
|
|
|
No, not fully. Could you explain it for?
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 800
|
|
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
Joined: Sep 30, 2012
Posts: 13
|
|
|
Thank you so much, again.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
Another link about ==
|
 |
 |
|
|
subject: Scanners put into if statements
|
|
|