0

Note: Please do not downvote question as I tried searching but did not find anything. The question has already been marked duplicate.

How to read primitive datatype values in Kotlin?

We can use Scanner object of java but I want to implement using readLine function of kotlin.

How do I scan numbers e.g num1 and num2 and perform some operation like sum ?

How do it convert following code to koltin without using scanner?

val sc = Scanner(System.in)
val num1 = sc.nextInt()
val num2 = sc.nextInt()
val sum = sum(num1, num2)
Akshar Patel
  • 7,525
  • 5
  • 31
  • 44

1 Answers1

1

Just do something like:

fun main(vararg args: String) {
  val (a, b) = readLine()!!.split(' ')
  println(a.toInt() + b.toInt())
}
Damián Rafael Lattenero
  • 14,625
  • 3
  • 30
  • 62