Kotlin作为BigInteger输入

Muh*_*gdi 4 input biginteger kotlin

我想要阅读两个50位数字并打印它们的总和,但我无法在Kotlin中获得BigInteger的输入.

  1. 如何以BigInteger的形式阅读Kotlin输入?
  2. 有没有其他方法可以解决这样的问题?

Ale*_*nov 9

您可以像在Java中一样进行:

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

print(first + second)
Run Code Online (Sandbox Code Playgroud)

或者您可以使用readLine()kotlin.io:

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

print(first + second)
Run Code Online (Sandbox Code Playgroud)