Consider the following conditional code, which returns a Boolean value:if ((x > 25) && (y > 100))
return 'false';
else if ((x <= 25) && (y <= 100))
return 'true';
else if ((x > 25) && (y <= 100))
return 'false';
else
return 'true';Simplify it by filling in the blank with a single Boolean expression without changing the behaviour of the code:if ( ________ )
return 'true';
else
return 'false';
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. x <= 25
Explanation
Output is 'true' for (x ≤ 25, y ≤ 100) and for the final else, which covers (x ≤ 25, y > 100). Both cases with x > 25 return 'false'. So the result is true exactly when x <= 25.More Programming Languages and Computer Graphics questions
- Machine level language is a/an
- Which of the following is wrong about data types?
- If a constructor 'Date' is declared explicit and has to be defined outside the class, which of the following is correct?
- Which one of the following allows the session to continue?
- Given a vector with Cartesian components (x, y), if scaling is done with the matrix [[0.5, 0], [0, 1.5]], which of the following are true?…
- Which of the following lists defined in HTML share a similar element? 1. Unordered lists 2. Ordered lists 3. Definition lists 4. Correlated…