Skip to content

Instantly share code, notes, and snippets.

@IEnoobong
Created November 6, 2017 09:07
Show Gist options
  • Save IEnoobong/4a7ba0c24907289f1872d632d684a6a0 to your computer and use it in GitHub Desktop.
Save IEnoobong/4a7ba0c24907289f1872d632d684a6a0 to your computer and use it in GitHub Desktop.
Before you go all functional
val sum = (0 until Integer.MAX_VALUE)
.map { it.toLong() }
.sum()
println(sum)
val sum = (0 until Integer.MAX_VALUE)
.asSequence()
.map { it.toLong() }
.sum()
println(sum)
var sum = 0L
for (i in 0..Integer.MAX_VALUE - 1) {
sum += i
}
println(sum)
var sum = 0L
for (i in 0 until Integer.MAX_VALUE) {
sum += i
}
println(sum)
Long sum = 0L;
for (long i = 0; i < Integer.MAX_VALUE; i++) {
sum += i;
}
System.out.println(sum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment