Input
Standard input
Section titled “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 = 0while (true) { val nextLine = readlnOrNull().takeUnless { it.isNullOrEmpty() } ?: break sum += nextLine.toInt()}println(sum)
El contingut d'aquest lloc web té llicència CC BY-NC-ND 4.0.
©2022-2025 xtec.dev