All mock tests are FREE till 31 December — register to save your progress
Unit 3 · Programming Languages and Computer Graphics Paper 2 CS · December 2022 Shift 2

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