Bird
0
0

You want to check if a number n is between 10 and 20 inclusive in Kotlin. Which expression correctly uses comparison operators?

hard📝 Application Q8 of 15
Kotlin - Operators and Expressions
You want to check if a number n is between 10 and 20 inclusive in Kotlin. Which expression correctly uses comparison operators?
An < 10 && n > 20
Bn > 10 || n < 20
Cn == 10 && n == 20
Dn >= 10 && n <= 20
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range condition

    To check if n is between 10 and 20 inclusive, it must be greater than or equal to 10 and less than or equal to 20.
  2. Step 2: Match the correct logical expression

    n >= 10 && n <= 20 uses n >= 10 && n <= 20, which correctly checks the range.
  3. Final Answer:

    n >= 10 && n <= 20 -> Option D
  4. Quick Check:

    Range check uses >= and <= with && [OK]
Quick Trick: Use && to combine range checks with >= and <= [OK]
Common Mistakes:
MISTAKES
  • Using || instead of &&
  • Using == instead of range operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes