Bird
0
0

What is the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Loops and Ranges
What is the output of this Kotlin code?
for (i in 1..3) {
  print(i)
}
A3 2 1
B1 2 3
CError: missing space
D123
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop and print function

    The loop runs from 1 to 3, printing each number without spaces or newlines.
  2. Step 2: Trace the output

    Prints 1, then 2, then 3 consecutively, resulting in "123".
  3. Final Answer:

    123 -> Option D
  4. Quick Check:

    print() outputs without spaces or newlines = C [OK]
Quick Trick: print() outputs inline; println() adds newline [OK]
Common Mistakes:
MISTAKES
  • Assuming print adds spaces
  • Confusing print with println
  • Expecting reversed output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes