Bird
0
0

What is the output of this Kotlin code?

medium📝 Predict Output Q13 of 15
Kotlin - Operators and Expressions
What is the output of this Kotlin code?
val x = 7
if (x in 1..5) println("Inside") else println("Outside")
AOutside
BCompilation error
CInside
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range check

    The range 1..5 includes numbers 1, 2, 3, 4, 5.
  2. Step 2: Check if x=7 is in the range

    7 is not between 1 and 5, so the condition is false.
  3. Final Answer:

    Outside -> Option A
  4. Quick Check:

    7 not in 1..5 means print "Outside" [OK]
Quick Trick: Check if value lies within range boundaries [OK]
Common Mistakes:
MISTAKES
  • Assuming 7 is inside 1..5
  • Confusing inclusive ranges with exclusive
  • Expecting a syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes