Bird
0
0

What is the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Operators and Expressions
What is the output of this Kotlin code?
val x = 4
if (x in 1..5) println("Yes") else println("No")
ANo output
BNo
CYes
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Check if x is in the range 1 to 5

    x is 4, which lies between 1 and 5 inclusive.
  2. Step 2: Determine output based on condition

    Since condition is true, it prints "Yes".
  3. Final Answer:

    Yes -> Option C
  4. Quick Check:

    'in' operator returns true if value is inside range [OK]
Quick Trick: If value in range, 'in' returns true [OK]
Common Mistakes:
MISTAKES
  • Assuming range excludes end values
  • Confusing output strings
  • Thinking 'in' checks only start

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes