Kotlin login as BigInteger

I want to read two 50 digit numbers and print their sum, but I cannot get the input to Kotlin as BigInteger.

  • How can I read the Kotlin input as BigInteger?
  • Is there any other way to solve this problem?
+3


source to share


1 answer


You can do it the same way as in Java :

val scanner = Scanner(System.`in`)
val first = scanner.nextBigInteger()
val second = scanner.nextBigInteger()

print(first + second)

      



OR you can use readLine()

from kotlin.io

:

val first = BigInteger(readLine())
val second = BigInteger(readLine())

print(first + second)

      

+9


source







All Articles