The question is: (5 == 10) || ((5 < 10) && !("wand".contains("an")))

Answer: true?

I'm not sure if I answered this correctly. And, I was wondering if anyone can explain how to tackle this question?

+15 votes

The answer in this case the answer would be false. We start by comparing the && statements because && has higher precedence than ||. When comparing it you should note that the left sided (5 < 10) is true but !("wand".contains("an")) would result as false because an is in wand therefore it is true but the ! operator makes it false. Now we can compare the left hand side(5 == 10) and note that it too is false. In the end we basically have a false statement (OR) a false statement, so the answer should be false.