0
0
Kotlinprogramming~10 mins

Non-nullable types by default 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 declare a non-nullable integer variable named age with value 30.

Kotlin
val age: Int = [1]
Drag options to blanks, or click blank then click option'
A30
Bnull
C"30"
D30L
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning null to a non-nullable type causes a compilation error.
Using quotes around numbers makes them strings, not integers.
2fill in blank
medium

Complete the code to declare a non-nullable string variable name with value "Alice".

Kotlin
val name: String = [1]
Drag options to blanks, or click blank then click option'
Anull
BAlice
C"Alice"
Dalice
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string literals.
Assigning null to a non-nullable variable.
3fill in blank
hard

Fix the error in the code by completing the declaration of a non-nullable Boolean variable isActive with value true.

Kotlin
val isActive: Boolean = [1]
Drag options to blanks, or click blank then click option'
Atrue
Bnull
C"true"
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase True instead of lowercase true.
Assigning null to a non-nullable variable.
Using quotes around Boolean values.
4fill in blank
hard

Fill both blanks to declare a non-nullable variable height of type Double with value 1.75.

Kotlin
val height: [1] = [2]
Drag options to blanks, or click blank then click option'
ADouble
B1.75
CFloat
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using Float instead of Double when the type is specified as Double.
Assigning null to a non-nullable variable.
5fill in blank
hard

Fill all three blanks to create a non-nullable variable score of type Int, assigned the value 100, and print it.

Kotlin
val [1]: [2] = [3]
println(score)
Drag options to blanks, or click blank then click option'
Ascore
BInt
C100
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using null as value for a non-nullable variable.
Mixing up the order of variable name, type, and value.