Bird
0
0

What will be printed by this Kotlin code?

medium📝 Predict Output Q5 of 15
Kotlin - Basics and JVM Runtime
What will be printed by this Kotlin code?
println("X")
print("Y")
println("Z")
AX YZ
BX Y Z
CXYZ
DXY Z
Step-by-Step Solution
Solution:
  1. Step 1: Analyze each print statement

    println("X") prints 'X' and newline, print("Y") prints 'Y' without newline, println("Z") prints 'Z' and newline.
  2. Step 2: Combine output lines

    First line: 'X', second line: 'Y' and 'Z' together because 'Y' has no newline, then 'Z' with newline.
  3. Final Answer:

    X YZ -> Option A
  4. Quick Check:

    print and println combined output = X\nYZ [OK]
Quick Trick: print stays on line, println moves down [OK]
Common Mistakes:
MISTAKES
  • Assuming print adds newline
  • Separating Y and Z incorrectly
  • Ignoring println newline

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes