Challenge - 5 Problems
Print and println Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of print and println combination
What is the output of this Kotlin code snippet?
Kotlin
fun main() { print("Hello") println("World") print("!") }
Attempts:
2 left
💡 Hint
Remember that print does not add a new line, but println does.
✗ Incorrect
The first print outputs "Hello" without a newline. Then println outputs "World" and adds a newline. Finally, print outputs "!" without a newline. So the combined output is "HelloWorld!" followed by a newline.
❓ Predict Output
intermediate2:00remaining
Output with multiple println calls
What will this Kotlin program print?
Kotlin
fun main() { println("A") println("B") println("C") }
Attempts:
2 left
💡 Hint
Each println adds a newline after printing.
✗ Incorrect
Each println prints the string and then moves to a new line. So the output is A, then newline, B, newline, C, newline.
🧠 Conceptual
advanced2:00remaining
Difference between print and println
Which statement best describes the difference between print() and println() in Kotlin?
Attempts:
2 left
💡 Hint
Think about what happens after the text is printed.
✗ Incorrect
print() writes text to the output without moving to a new line, so the next output continues on the same line. println() writes text and then moves to the next line.
❓ Predict Output
advanced2:00remaining
Output of mixed print and println with variables
What is the output of this Kotlin code?
Kotlin
fun main() { val x = 5 print("x = $x") println(", x squared = ${x * x}") print("Done") }
Attempts:
2 left
💡 Hint
Remember where println adds a newline.
✗ Incorrect
print("x = $x") outputs "x = 5" without newline. println then outputs ", x squared = 25" and adds a newline. Finally, print("Done") outputs "Done" on the new line.
❓ Predict Output
expert2:00remaining
Output of nested print and println calls
What is the output of this Kotlin program?
Kotlin
fun main() { print("Start") println() print("End") }
Attempts:
2 left
💡 Hint
What does println() with no arguments do?
✗ Incorrect
print("Start") outputs "Start" with no newline. println() with no arguments outputs just a newline. Then print("End") outputs "End" on the new line. So output is Start, newline, newline, End.