Skip to content
Justice Tech School

Kotlin Input and Output

println prints with a newline and print does not. readLine() reads a line of input and returns String?. Convert with toInt() or toIntOrNull().

Example
val line = readLine() ?: ""
val n = line.toIntOrNull() ?: 0
print("Value: ")
println(n + 1)

Exercise

Safe conversion.

"12".()

Quiz Test

Which conversion never throws?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.