stackquestions stackquestions - 1 year ago 96
Java Question

Java boolean statement with OR operator trouble

int optionselect = 3;
System.out.println(optionselect != 1 || optionselect != 2 || optionselect != 3);

This statement is printing true for me no matter what I set the int optionselect to. I'm not sure how or why.

Answer Source

It's always going to not equal at least 2 of those, because it can only equal 1 of them at a time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download