0
0
Kotlinprogramming~10 mins

Operator precedence 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 calculate the correct result using operator precedence.

Kotlin
val result = 3 + 4 * [1]
Drag options to blanks, or click blank then click option'
A1
B2
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 3 + 4 first, then multiplying by the number.
Ignoring operator precedence and calculating left to right.
2fill in blank
medium

Complete the code to get the correct boolean result using operator precedence.

Kotlin
val isTrue = true || false && [1]
Drag options to blanks, or click blank then click option'
Afalse
Btrue
Cnull
Dtrue && false
Attempts:
3 left
💡 Hint
Common Mistakes
Evaluating || before &&.
Using an expression instead of a boolean value.
3fill in blank
hard

Fix the error in the expression by completing the code with the correct operator.

Kotlin
val value = 10 + 5 [1] 3
Drag options to blanks, or click blank then click option'
A/
B%
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction (-) or division (/) which changes the result.
Using modulo (%) which is not intended here.
4fill in blank
hard

Fill both blanks to create a map of words to their lengths only if length is greater than 3.

Kotlin
val lengths = mapOf([1] to [2]).filter { it.value > 3 }
Drag options to blanks, or click blank then click option'
A"apple"
B"banana"
C"apple".length
D"banana".length
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same word for key and length causing confusion.
Not using quotes for string keys.
5fill in blank
hard

Fill all three blanks to create a filtered map with uppercase keys and values greater than 4.

Kotlin
val filtered = mapOf([1] to [2]).filter { it.value [3] 4 }
Drag options to blanks, or click blank then click option'
A"pear".uppercase()
B5
C>
D"plum".uppercase()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase strings instead of uppercase.
Using wrong comparison operators like < or ==.