Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert an Int to a Double explicitly.
Kotlin
val number: Int = 10 val converted: Double = number.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using toInt() which does not change the type.
Using toString() which converts to text, not a number.
Using toFloat() which converts to Float, not Double.
✗ Incorrect
In Kotlin, to convert an Int to a Double explicitly, you use the toDouble() function.
2fill in blank
mediumComplete the code to convert a Double to an Int explicitly.
Kotlin
val decimal: Double = 9.99 val whole: Int = decimal.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using toDouble() which keeps the type as Double.
Using toLong() which converts to Long, not Int.
Using toFloat() which converts to Float, not Int.
✗ Incorrect
To convert a Double to an Int explicitly in Kotlin, use the toInt() function.
3fill in blank
hardFix the error in the code by explicitly converting the Int to a Double.
Kotlin
val a: Int = 5 val b: Double = a[1] 2.0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to multiply Int and Double directly without conversion.
Using only the '*' operator without conversion.
Using '+' operator which changes the operation.
✗ Incorrect
You must convert 'a' to Double explicitly before multiplying by 2.0. So use 'a.toDouble() * 2.0'.
4fill in blank
hardFill both blanks to convert a String to Int and then add 10.
Kotlin
val input: String = "20" val result: Int = input.[1]() [2] 10
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using toDouble() instead of toInt() for conversion.
Using '-' instead of '+' for addition.
Trying to add 10 to a String without conversion.
✗ Incorrect
First convert the String to Int using toInt(), then add 10 using '+'.
5fill in blank
hardFill all three blanks to convert a Double to Int, then to String, and concatenate " apples".
Kotlin
val price: Double = 5.99 val text: String = price.[1]().[2]() + [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Skipping conversion steps and trying to add string to Double directly.
Using toDouble() instead of toInt() first.
Forgetting to convert Int to String before concatenation.
✗ Incorrect
Convert Double to Int with toInt(), then Int to String with toString(), then add the text " apples".