Reputation: 11
how can i take an int or float or any numeric input from user except String because .readline() only take String as an input . for example i want to take numbers from user in this example:
println"Enter your age"
var age:int =readInt()
This gives me an error
Upvotes: 1
Views: 1277
Reputation: 3
To get input from a user, try:
fun main(args: Array<String>) {
val input = readLine()
println(input)
}
Hope I helped!
Upvotes: 0
Reputation: 17500
You can also do the following:
fun main() {
with(Scanner(System.`in`)) {
val a = nextInt()
println(a)
}
}
Upvotes: 0
Reputation: 886
fun main() {
val num = readLine()!!
println(num.toInt())
}
You can read the input as string and then convert it to the data type you want later
Upvotes: 1