Complete the code to declare a function that accepts a variable number of integers.
fun printNumbers([1] numbers: Int) { for (number in numbers) { println(number) } }
The vararg keyword allows the function to accept a variable number of arguments.
Complete the code to call the function with multiple integer arguments.
printNumbers([1])When calling a function with vararg parameters, you can pass multiple arguments separated by commas.
Fix the error in calling the function with an array argument.
val nums = intArrayOf(4, 5, 6) printNumbers([1] nums)
Use the spread operator * before the array to pass its elements as separate arguments.
Fill both blanks to define a function that accepts a string and a variable number of integers.
fun showDetails(name: String, [1] numbers: [2]) { println("Name: $name") for (num in numbers) { println(num) } }
IntArray or Array instead of the element type.vararg keyword.The vararg keyword is used before the parameter name, and the type is Int for variable integers.
Fill all three blanks to create a function that sums variable integers and returns the result.
fun sumNumbers([1] nums: [2]): [3] { var total = 0 for (n in nums) { total += n } return total }
Double as return type when summing integers.vararg keyword.The function uses vararg for variable arguments of type Int and returns an Int sum.