0
0
Android Kotlinmobile~10 mins

Data types and type inference in Android 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 declare a variable with type inference holding the number 10.

Android Kotlin
val number = [1]
Drag options to blanks, or click blank then click option'
A10
B"10"
C10.0
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Putting 10 in quotes makes it a string, not a number.
Using 10.0 makes it a Double, not an Int.
2fill in blank
medium

Complete the code to explicitly declare a variable of type Double with value 3.14.

Android Kotlin
val pi: [1] = 3.14
Drag options to blanks, or click blank then click option'
AInt
BDouble
CString
DBoolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int will cause a type mismatch error.
Using String or Boolean is incorrect for numbers.
3fill in blank
hard

Fix the error in the code by choosing the correct type for the variable holding true.

Android Kotlin
val isActive: [1] = true
Drag options to blanks, or click blank then click option'
AInt
BString
CBoolean
DDouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int or Double causes type mismatch errors.
Using String is incorrect because true is not text.
4fill in blank
hard

Fill both blanks to declare a mutable variable of type String with value "Hello".

Android Kotlin
var greeting: [1] = [2]
Drag options to blanks, or click blank then click option'
AString
B"Hello"
CInt
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int or Boolean types for text variables.
Not putting the string value in quotes.
5fill in blank
hard

Fill all three blanks to create a read-only variable with type inferred as Int and value 42.

Android Kotlin
val [1] = [2] // inferred type is [3]
Drag options to blanks, or click blank then click option'
Aanswer
B42
CInt
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string or boolean value instead of a number.
Choosing a variable name that is not descriptive.