I am coding a simple program using a scanner and now want to make sure the user only types "yes" or "no" by comparing the input to these words. I'm using a normal if
-statement with ||
(pipes):
if (!input.equals("yes") || !input.equals("no")) {
//do something
}
Java (I am using BlueJ) complains about my pipes, it says: "illegal character: '\u00a0'"
What I tried
Does anyone have an idea why it complains and how I can fix it? – Thanks in advance
The character u00a0
is a non-breaking space.
It seems like you typed a control char in your code, replace everything from a copy of this line
if(!input.equals("yes") && !input.equals("no"))
Or simply suppress the spaces in your line and re-type them (making sure you don't type in nbsp
).
Notice that I changed the ||
to &&
as typing "no" for example would still enter the condition as "yes" would not equals to input. Your condition would then be true || false
which would result in true
.
In any case, this is not related to the ||
or &&
operator, it is the spaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With