0
0
Kotlinprogramming~20 mins

Operator precedence in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Operator Precedence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Kotlin code involving mixed operators?

Consider the following Kotlin code snippet:

val result = 3 + 4 * 2 / (1 - 5) % 2
println(result)

What will be printed?

Kotlin
val result = 3 + 4 * 2 / (1 - 5) % 2
println(result)
A2
B1
C0
D3
Attempts:
2 left
💡 Hint

Remember the order: parentheses, multiplication/division/modulus, then addition/subtraction.

Predict Output
intermediate
2:00remaining
What is the value of x after this Kotlin expression?

Given this Kotlin code:

var x = 10
x += 3 * 2 - 4 / 2

What is the value of x after running this?

Kotlin
var x = 10
x += 3 * 2 - 4 / 2
println(x)
A15
B16
C14
D17
Attempts:
2 left
💡 Hint

Calculate multiplication and division before addition and subtraction.

Predict Output
advanced
2:00remaining
What does this Kotlin code print with logical and arithmetic operators?

Analyze this Kotlin code:

val a = true
val b = false
val c = 5
val d = 10
val result = a && b || c < d && !b
println(result)

What is the output?

Kotlin
val a = true
val b = false
val c = 5
val d = 10
val result = a && b || c < d && !b
println(result)
Afalse
Btrue
CCompilation error
DRuntime exception
Attempts:
2 left
💡 Hint

Remember that && has higher precedence than ||, and ! has highest precedence.

Predict Output
advanced
2:00remaining
What is the output of this Kotlin code with mixed increment and arithmetic?

Consider this Kotlin snippet:

var x = 5
val y = x++ * 2 + --x
println(y)

What will be printed?

Kotlin
var x = 5
val y = x++ * 2 + --x
println(y)
A15
B23
C29
D25
Attempts:
2 left
💡 Hint

Remember post-increment returns the value before increment, pre-decrement decrements before use.

Predict Output
expert
2:00remaining
What is the output of this Kotlin code with chained assignments and operator precedence?

Analyze this Kotlin code:

var a = 2
var b = 3
var c = 4
val result = a + b * c / a - b % c
println(result)

What will be printed?

Kotlin
var a = 2
var b = 3
var c = 4
val result = a + b * c / a - b % c
println(result)
A5
B7
C6
D4
Attempts:
2 left
💡 Hint

Follow operator precedence: multiplication/division/modulus before addition/subtraction.