2
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?

daniele3004
  • 10,770
  • 9
  • 55
  • 63
sandip4069
  • 41
  • 1
  • 5
  • 1
    As evident by the fundamentally differing answers, you should edit your question to include some context. What would this supposed `Long Long` do for you that `Long` doesn't? – chris Oct 23 '17 at 18:57
  • 1
    Java itself has no `long long` type. `long` is 64-bit, `int` is 32-bit, `short` is 16-bit and `byte` is 8-bit. Kotlin doesn't change this. – Moira Oct 23 '17 at 19:57

3 Answers3

9

Kotlin's Long is 64-bit already. No need for ancient long long trickery:

https://kotlinlang.org/docs/reference/basic-types.html

Marcin Orlowski
  • 67,279
  • 10
  • 112
  • 132
2

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.

zsmb13
  • 69,803
  • 10
  • 174
  • 178
0

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)
    } 
}