0
0
Kotlinprogramming~10 mins

Array creation and usage in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an array of integers with values 1, 2, and 3.

Kotlin
val numbers = arrayOf([1])
Drag options to blanks, or click blank then click option'
A1 2 3
B1, 2, 3
C[1, 2, 3]
D(1, 2, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting commas between values.
Using square brackets instead of parentheses.
2fill in blank
medium

Complete the code to access the second element of the array named fruits.

Kotlin
val secondFruit = fruits[[1]]
Drag options to blanks, or click blank then click option'
A0
B-1
C2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 1 for the second element index.
Using negative indices which are not valid in Kotlin arrays.
3fill in blank
hard

Fix the error in the code to create an array of size 5 filled with zeros.

Kotlin
val zeros = Array([1] = 5) { 0 }
Drag options to blanks, or click blank then click option'
Acount
Blength
Csize
Dcapacity
Attempts:
3 left
💡 Hint
Common Mistakes
Using length or count which are not parameter names here.
Using capacity which is not valid for Kotlin arrays.
4fill in blank
hard

Fill both blanks to create an array of strings with values "apple", "banana", and "cherry".

Kotlin
val fruits = arrayOf([1]) // Create array
val firstFruit = fruits[[2]] // Access first element
Drag options to blanks, or click blank then click option'
A"apple", "banana", "cherry"
B0
C1
D"apple"
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 to access the first element.
Not using quotes around string values.
5fill in blank
hard

Fill all three blanks to create an array of integers from 1 to 5, square each number, and filter out squares greater than 10.

Kotlin
val numbers = arrayOf(1, 2, 3, 4, 5)
val squares = numbers.map { it [1] [2] }
val filtered = squares.filter { it [3] 10 }
Drag options to blanks, or click blank then click option'
A*
Bit
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication for squaring.
Using wrong comparison operators in filter.