0

How can I input a String and an int in the same line? how do i make n an Int?

val (s, n) = readln().split(" ")

Sample Input

Hello 3

  • Does this answer your question? [Reading console input in Kotlin](https://stackoverflow.com/questions/41283393/reading-console-input-in-kotlin) – droebi Aug 29 '22 at 10:17

2 Answers2

1

I would split it in two lines. For example:

val (s, _n) = readln().split(" ")
val n = _n.toInt()
Ivo
  • 18,659
  • 2
  • 23
  • 35
0
val (s, n) = with(readln().split(" ")) { this[0] to this[1].toInt() }
Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42