Adrian Bong
Adrian Bong

Reputation: 1

Input string & Int in the same line kotlin

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

Upvotes: 0

Views: 180

Answers (2)

Nikolai  Shevchenko
Nikolai Shevchenko

Reputation: 7521

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

Upvotes: 0

Ivo
Ivo

Reputation: 23267

I would split it in two lines. For example:

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

Upvotes: 1

Related Questions