Bird
0
0

What is the output of the following Kotlin code?

medium📝 Predict Output Q13 of 15
Kotlin - Control Flow as Expressions
What is the output of the following Kotlin code?
val x = 5
val result = if (x % 2 == 0) "Even" else "Odd"
println(result)
AEven
B5
COdd
DSyntaxError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition x % 2 == 0

    Since 5 % 2 equals 1, the condition is false.
  2. Step 2: Determine which branch executes

    Because the condition is false, the else branch returns "Odd".
  3. Final Answer:

    Odd -> Option C
  4. Quick Check:

    5 is odd = C [OK]
Quick Trick: Check condition result carefully to pick correct branch [OK]
Common Mistakes:
MISTAKES
  • Assuming 5 is even
  • Ignoring else branch
  • Confusing modulo operation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes