Home > Enterprise >  Input string & Int in the same line kotlin
Input string & Int in the same line kotlin

Time:08-30

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

CodePudding user response:

I would split it in two lines. For example:

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

CodePudding user response:

val (s, n) = with(readln().split(" ")) { this[0] to this[1].toInt() }
  • Related