0
0
Kotlinprogramming~10 mins

Why Kotlin has no primitive types at source level - Test Your Understanding

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

Complete the code to declare a variable of type Int in Kotlin.

Kotlin
val number: [1] = 10
Drag options to blanks, or click blank then click option'
AprimitiveInt
BInt
Cint
DInteger
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'int' which is not valid in Kotlin source code.
2fill in blank
medium

Complete the code to create a list of integers in Kotlin.

Kotlin
val numbers = listOf(1, 2, 3).map { it [1] 2 }
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' which adds instead of multiplying.
3fill in blank
hard

Fix the error in the Kotlin function that returns the sum of two numbers.

Kotlin
fun sum(a: Int, b: Int): Int {
    return a [1] b
}
Drag options to blanks, or click blank then click option'
A/
B-
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which subtracts instead of adding.
4fill in blank
hard

Fill both blanks to create a map of words to their lengths, filtering words longer than 3 characters.

Kotlin
val words = listOf("cat", "house", "dog", "elephant")
val lengths = words.filter { it.length [1] 3 }.associateWith { it.[2] }
Drag options to blanks, or click blank then click option'
A>
Blength
C<
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which filters shorter words.
Using 'count' which is a function, not a property.
5fill in blank
hard

Fill all three blanks to create a map of uppercase words to their lengths, filtering words with length greater than 4.

Kotlin
val words = listOf("apple", "bat", "carrot", "dog")
val result = words.filter { it.[1] [2] 4 }.associate { it.[3] to it.length }
Drag options to blanks, or click blank then click option'
Alength
B>
Cuppercase
Duppercase()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'uppercase' without parentheses which is not a function call.
Using '<' instead of '>' for filtering.