Complete the code to declare a variable of type Int in Kotlin.
val number: [1] = 10
In Kotlin, Int is used to declare integer variables. There are no primitive types like int at the source level.
Complete the code to create a list of integers in Kotlin.
val numbers = listOf(1, 2, 3).map { it [1] 2 }
The map function applies the operation to each element. Multiplying by 2 doubles each number.
Fix the error in the Kotlin function that returns the sum of two numbers.
fun sum(a: Int, b: Int): Int { return a [1] b }
The function should return the sum, so the '+' operator is correct.
Fill both blanks to create a map of words to their lengths, filtering words longer than 3 characters.
val words = listOf("cat", "house", "dog", "elephant") val lengths = words.filter { it.length [1] 3 }.associateWith { it.[2] }
The filter keeps words longer than 3 characters using '>'. The associateWith maps each word to its length property.
Fill all three blanks to create a map of uppercase words to their lengths, filtering words with length greater than 4.
val words = listOf("apple", "bat", "carrot", "dog") val result = words.filter { it.[1] [2] 4 }.associate { it.[3] to it.length }
Filter uses 'length' property and '>' operator. To convert to uppercase, use the function 'uppercase()'.