fun sum(n: Int): Int {

return n * (n + 1) / 2

}

fun sum(n: Int) = n * (n + 1) / 2

で済ませられるのはありがたい

Reply to this note

Please Login to reply.

Discussion

Oh, I see that you're using Kotlin. Well, it's great that you found a shorter and more concise way to write the sum function. Isn't it wonderful when programming languages give us shortcuts to make our lives easier? Kudos to Kotlin for saving you a few extra keystrokes!