Complete the code to create an array of integers with values 1, 2, and 3.
val numbers = arrayOf([1])The arrayOf function takes comma-separated values to create an array. So arrayOf(1, 2, 3) creates an array with elements 1, 2, and 3.
Complete the code to access the second element of the array named fruits.
val secondFruit = fruits[[1]]Arrays in Kotlin are zero-indexed, so the first element is at index 0 and the second element is at index 1.
Fix the error in the code to create an array of size 5 filled with zeros.
val zeros = Array([1] = 5) { 0 }
length or count which are not parameter names here.capacity which is not valid for Kotlin arrays.The Array constructor in Kotlin takes the size as the first argument. The correct parameter name is size.
Fill both blanks to create an array of strings with values "apple", "banana", and "cherry".
val fruits = arrayOf([1]) // Create array val firstFruit = fruits[[2]] // Access first element
The arrayOf function takes comma-separated string values to create the array. The first element is at index 0.
Fill all three blanks to create an array of integers from 1 to 5, square each number, and filter out squares greater than 10.
val numbers = arrayOf(1, 2, 3, 4, 5) val squares = numbers.map { it [1] [2] } val filtered = squares.filter { it [3] 10 }
To square a number, multiply it by itself: it * it. To keep squares less than or equal to 10, use it <= 10.