Printing Output
Prerequisites: Kotlin syntax basics
println prints a value and ends the line; print prints without
ending the line.
Example
fun main() {
println("Hello")
print("Same ")
print("line")
println()
println(42)
println(3.5)
println(true)
println(listOf(1, 2, 3))
println("A" + "B")
}
Expected output
Hello
Same line
42
3.5
true
[1, 2, 3]
AB
println()with nothing just ends the current line.- Any value can be printed: numbers,
true/false, and collections, which print in square brackets.
To print several values on one line, build a single string with a string template — covered in the Strings lesson:
fun main() {
val city = "Oslo"
val temp = 21
println("$city: $temp°C")
}
Oslo: 21°C
Practice
Print Loading... and then done on the same line, followed by a new
line.
Show solution
fun main() {
print("Loading...")
println("done")
}