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 a = 20
val b = 6
println(a / b)
A3.3333333
BError
C3.0
D3
Step-by-Step Solution
Solution:
  1. Step 1: Understand integer division in Kotlin

    Both a and b are integers, so division returns an integer result by truncation.
  2. Step 2: Calculate 20 divided by 6

    20 / 6 = 3.333..., truncated to 3 as integer division.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Integer division result = 3 [OK]
Quick Trick: Integer division drops decimals, use Double for float [OK]
Common Mistakes:
MISTAKES
  • Expecting decimal result
  • Using floating point division without casting
  • Assuming error occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes