Complete the code to convert the string "123" to an integer.
val number = "123".[1]()
The toInt() function converts a string to an integer in Kotlin.
Complete the code to convert the string "45.67" to a double number.
val decimalNumber = "45.67".[1]()
The toDouble() function converts a string to a double-precision floating point number.
Fix the error in the code to safely convert a string to an integer without crashing.
val input = "abc" val number = input.[1]() ?: 0
toIntOrNull() tries to convert the string to an integer and returns null if it fails, avoiding a crash.
Fill both blanks to create a map of words to their lengths, but only include words longer than 3 characters.
val words = listOf("cat", "house", "tree", "a") val lengths = words.associateWith { it.[1] }.filter { it.value [2] 3 }
The length property returns the number of characters in the string, and > filters words longer than 3.
Fill all three blanks to create a map of uppercase words to their integer lengths, only for words with length greater than 2.
val words = listOf("dog", "cat", "a", "bird") val result = words.filter { it.[1] [2] 2 }.associate { it.[3]() to it.length }
length gets the word length, > filters words longer than 2, and uppercase() converts words to uppercase keys.