The condition num! =65 cannot be replaced by
2022
The condition num! =65 cannot be replaced by
- A.
num >65 || num <65
- B.
!( num ==65)
- C.
num −65
- D.
!(num−65)
Attempted by 990 students.
Show answer & explanation
Correct answer: D
Goal: determine which expression cannot replace the condition num != 65.
Key insight: an expression can replace num != 65 only if it evaluates to true exactly when num is not equal to 65.
num > 65 || num < 65: This checks whether
numis either greater than or less than 65, which precisely meansnum ≠ 65. Hence, it is equivalent.!(num == 65): Negating the equality condition gives true when
numis not 65. Hence, it is equivalent.num - 65: In languages like C/C++, nonzero values are treated as true and zero as false. This expression becomes zero only when
num == 65, so it behaves likenum != 65. However, in strongly typed languages (like Java), this is invalid as a boolean condition.!(num - 65): This becomes true only when
num - 65 == 0, i.e., whennum == 65. Hence, it representsnum == 65, which is the opposite ofnum != 65.
Conclusion: The expression !(num - 65) cannot replace num != 65 because it evaluates to true when num equals 65, not when it is different.
A video solution is available for this question — log in and enroll to watch it.