Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Control Flow as Expressions
What will be the output of this Kotlin code?
val num = 10
val result = if (num % 2 == 0) "Even" else "Odd"
println(result)
AEven
B10
COdd
Dnum % 2 == 0
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition num % 2 == 0

    10 divided by 2 leaves remainder 0, so condition is true.
  2. Step 2: Determine which branch executes

    Since condition is true, "Even" is assigned to result and printed.
  3. Final Answer:

    Even -> Option A
  4. Quick Check:

    Condition true returns "Even" = C [OK]
Quick Trick: Check condition result carefully to pick correct branch [OK]
Common Mistakes:
MISTAKES
  • Confusing remainder operation
  • Printing variable name instead of value
  • Mixing up true and false branches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes