1

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

4 Answers 4

1
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

Sign up to request clarification or add additional context in comments.

Comments

0

You can also do the following:

fun main() {
    with(Scanner(System.`in`)) {
       val a = nextInt()
       println(a)
    }
}

Comments

0

To get input from a user, try:

fun main(args: Array<String>) {
    val input = readLine()
    println(input)
}

Hope I helped!

Comments

0

Input Int in Kotlin var input:Int=Integer.valueOf(readLine())

1 Comment

var a:Int=Integer.valueOf(readLine())

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.