Complete the code to concatenate two strings using the + operator.
val greeting = "Hello, " [1] "World!"
In Kotlin, the + operator is used to join (concatenate) strings.
Complete the code to use a string template to insert the variable name into the greeting.
val name = "Alice" val greeting = "Hello, [1]!"
In Kotlin, string templates use the $ symbol before a variable name to insert its value inside a string.
Fix the error in the string template to correctly include the variable age.
val age = 30 val message = "I am [1] years old."
When inserting expressions or variables in Kotlin strings, use ${variable} to clearly mark the variable inside the string.
Fill both blanks to create a map of words to their lengths, using string templates and a condition.
val words = listOf("apple", "bat", "carrot") val lengths = {word: [1] for word in words if word.length [2] 3}
The map uses word.length to get the length of each word. The condition filters words longer than 3 characters using >.
Fill all three blanks to create a message using string templates with expressions.
val x = 5 val y = 10 val message = "Sum of [1] and [2] is [3]"
Use $x and $y to insert variables, and ${x + y} to insert the sum expression inside the string.