0
0
Kotlinprogramming~10 mins

Type conversion is always explicit in Kotlin - Interactive Code Practice

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

Complete 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'
AtoFloat
BtoString
CtoDouble
DtoInt
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.
2fill in blank
medium

Complete 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'
AtoInt
BtoLong
CtoFloat
DtoDouble
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.
3fill in blank
hard

Fix 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'
A+
B.toDouble() *
C/
D*
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.
4fill in blank
hard

Fill 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'
AtoInt
B+
C-
DtoDouble
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.
5fill in blank
hard

Fill 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'
AtoInt
BtoString
C" apples"
DtoDouble
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.