0
0
Kotlinprogramming~20 mins

Array creation and usage in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Kotlin code?
Consider the following Kotlin code snippet. What will it print when run?
Kotlin
val arr = arrayOf(1, 2, 3, 4)
println(arr[2])
A3
B2
C4
DIndexOutOfBoundsException
Attempts:
2 left
💡 Hint
Remember that Kotlin arrays are zero-indexed.
Predict Output
intermediate
2:00remaining
What does this Kotlin code print?
Look at this Kotlin code. What is the output?
Kotlin
val arr = IntArray(3) { it * 2 }
println(arr.joinToString(","))
A0,2,4
B1,2,3
C0,1,2
D2,4,6
Attempts:
2 left
💡 Hint
The lambda uses the index to calculate each element.
Predict Output
advanced
2:00remaining
What is the output of this Kotlin code with array mutation?
What will this Kotlin code print?
Kotlin
val arr = arrayOf("a", "b", "c")
arr[1] = "z"
println(arr.joinToString())
Aa, b, c
Ba, z, c
Ca, z, b
DCompilation error
Attempts:
2 left
💡 Hint
Arrays in Kotlin are mutable by default.
Predict Output
advanced
2:00remaining
What error does this Kotlin code produce?
What happens when this Kotlin code runs?
Kotlin
val arr = arrayOf(1, 2, 3)
println(arr[3])
APrints 3
BPrints null
CArrayIndexOutOfBoundsException
DCompilation error
Attempts:
2 left
💡 Hint
Check the valid indices for the array.
🧠 Conceptual
expert
2:00remaining
How many elements does this Kotlin array contain?
Given this Kotlin code, how many elements are in the array 'arr'?
Kotlin
val arr = Array(5) { i -> i * i }
A0
B4
C6
D5
Attempts:
2 left
💡 Hint
The first argument to Array() is the size.