Bird
0
0

What will be printed by this Kotlin code?

medium📝 Predict Output Q5 of 15
Kotlin - Operators and Expressions
What will be printed by this Kotlin code?
val x = 10
val y = 5
val z = x - y * 2 + 3
println(z)
A8
B13
C3
D7
Step-by-Step Solution
Solution:
  1. Step 1: Calculate multiplication first

    y * 2 = 5 * 2 = 10.
  2. Step 2: Evaluate subtraction and addition left to right

    x - 10 + 3 = 10 - 10 + 3 = 0 + 3 = 3.
  3. Step 3: Re-check calculation

    Wait, re-check: 10 - (5*2) + 3 = 10 - 10 + 3 = 3.
  4. Final Answer:

    3 -> Option C
  5. Quick Check:

    Multiplication before addition and subtraction [OK]
Quick Trick: Multiply before subtracting or adding [OK]
Common Mistakes:
MISTAKES
  • Adding before multiplying
  • Misordering operations
  • Incorrect left-to-right evaluation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes