How can I read an integer value from the user to use in the range of a for loop?
fun main() { var n = readLine() for (i in 1..n) { var (a, b) = readLine()!!.split(' ') println(a.toInt() + b.toInt()) } } How can I read an integer value from the user to use in the range of a for loop?
fun main() { var n = readLine() for (i in 1..n) { var (a, b) = readLine()!!.split(' ') println(a.toInt() + b.toInt()) } } You can use the String.toInt() function to achieve this (the same thing that you doing in later lines).
Like this:
fun main() { val n = readLine()!!.toInt() for (i in 1..n) { val (a, b) = readLine()!!.split(' ') println(a.toInt() + b.toInt()) } } Also, you can replace your vars with vals since they are not changed anywhere.