Reputation: 61
fun main(args: Array<String>) {
try {
var sum: Long = 0
val n: Int = readLine()!!.toInt()
for (i in 0..(n - 1)) {
var input: Long?
input = readLine()!!.toLong()
sum += input
}
println(sum)
} catch (ex: Exception) {
println(ex.message)
}
}
I want to take data Type Long Long replacing at Long . So how can I define Long Long data type?
Upvotes: 3
Views: 14418
Reputation: 1
Kotlin handles long long data type with the BigInteger data type. Replace the long with BigInteger;
fun main(args: Array<String>) {
try {
var sum = 0.toBigInteger()
val n: Int = readLine()!!.toInt()
for (i in 0..(n - 1)) {
var input: BigInteger?
input = readLine()!!.toBigInteger()
sum += input
}
println(sum)
} catch (ex: Exception) {
println(ex.message)
}
}
Upvotes: 0
Reputation: 89678
If you're on the JVM, there isn't a long long
type, but you could use java.math.BigInteger
for arbitrarily large numbers instead.
See more discussion on this topic and some more alternatives at a Java question here.
Upvotes: 2
Reputation: 75645
Kotlin's Long
is 64-bit already. No need for ancient long long
trickery:
https://kotlinlang.org/docs/reference/basic-types.html
Upvotes: 9