Added a Kotlin variation.
This commit is contained in:
parent
64c9e43742
commit
a8cbadbe7d
|
@ -1,10 +1,10 @@
|
||||||
fun protectedInput(variableName: String): Int {
|
fun protectedInput(variableName: String): Int {
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
print("Enter $variableName: ");
|
print("Enter $variableName: ")
|
||||||
return readln().toInt()
|
return readln().toInt()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
println("${variableName.uppercase()} must be an integer!");
|
println("${variableName.uppercase()} must be an integer!")
|
||||||
}
|
}
|
||||||
} while (true)
|
} while (true)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue