作为 BigInteger 的 Kotlin 输入
Kotlin input as a BigInteger
我想读取两个 50 位数字并打印它们的总和,但我无法在 Kotlin 中将输入作为 BigInteger。
- 如何将 Kotlin 输入读取为 BigInteger?
- 有没有其他方法可以解决这样的问题?
您可以按照 Java 中的方式进行操作:
val scanner = Scanner(System.`in`)
val first = scanner.nextBigInteger()
val second = scanner.nextBigInteger()
print(first + second)
或 您可以使用 kotlin.io
中的 readLine()
:
val first = BigInteger(readLine())
val second = BigInteger(readLine())
print(first + second)
我想读取两个 50 位数字并打印它们的总和,但我无法在 Kotlin 中将输入作为 BigInteger。
- 如何将 Kotlin 输入读取为 BigInteger?
- 有没有其他方法可以解决这样的问题?
您可以按照 Java 中的方式进行操作:
val scanner = Scanner(System.`in`)
val first = scanner.nextBigInteger()
val second = scanner.nextBigInteger()
print(first + second)
或 您可以使用 kotlin.io
中的 readLine()
:
val first = BigInteger(readLine())
val second = BigInteger(readLine())
print(first + second)