fun sum(n: Int): Int {
return n * (n + 1) / 2
}
を
fun sum(n: Int) = n * (n + 1) / 2
で済ませられるのはありがたい
fun sum(n: Int): Int {
return n * (n + 1) / 2
}
を
fun sum(n: Int) = n * (n + 1) / 2
で済ませられるのはありがたい
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!