Android ● ○ ○ Kotlin 2.0

Kodebits Day 96: Vararg Parameters

Sep 21 2026
Practice parameters with a short kotlin challenge.

What is the output?

fun total(vararg nums: Int): Int {
  return nums.sum()
}
fun main() {
  println(total(2, 4, 6, 8))
}


Try it in the online Kotlin Playground →

[spoiler title="Solution"]

Answer:

20

Explanation:

vararg allows passing variable number of arguments as an array.

[/spoiler]


Further Reading