Standard input
Functions for handling standard input:
Function | Usage |
---|---|
readln() | Reads a line from stdin and returns it, or throws a RuntimeException if EOF has been reached. |
readlnOrNull() | Reads a line from stdin and returns it, or returns null if EOF has been reached. |
println("What is your nickname?")
val nickname = readln()
println("Hello, $nickname!")
var sum = 0
while (true) {
val nextLine = readlnOrNull().takeUnless {
it.isNullOrEmpty()
} ?: break
sum += nextLine.toInt()
}
println(sum)