Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+14 votes

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?

asked in CSC211_Winter2018 by (8 points)

1 Answer

+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.

answered by (8 points)