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]