0
0
Kotlinprogramming~20 mins

Arithmetic operators in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Arithmetic Operator 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?
Consider the following Kotlin code snippet. What will it print when run?
Kotlin
fun main() {
    val a = 10
    val b = 3
    println(a / b)
}
A3
B3.3333333
C3.0
D4
Attempts:
2 left
💡 Hint
Remember that dividing two integers in Kotlin results in an integer division.
Predict Output
intermediate
2:00remaining
What is the output of this Kotlin code with mixed types?
What will this Kotlin program print?
Kotlin
fun main() {
    val x = 7
    val y = 2.0
    println(x / y)
}
A3
B3.50
C3.0
D3.5
Attempts:
2 left
💡 Hint
When dividing an Int by a Double, Kotlin promotes the Int to Double.
Predict Output
advanced
2:00remaining
What is the output of this Kotlin code using the modulus operator?
Analyze the following Kotlin code and select the output it produces.
Kotlin
fun main() {
    val a = 17
    val b = 5
    println(a % b)
}
A1
B3
C2
D0
Attempts:
2 left
💡 Hint
The modulus operator (%) gives the remainder after division.
Predict Output
advanced
2:00remaining
What is the output of this Kotlin code with mixed arithmetic and assignment?
What will be printed by this Kotlin program?
Kotlin
fun main() {
    var n = 8
    n += 3 * 2
    println(n)
}
A14
B16
C22
D11
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication before addition.
Predict Output
expert
2:00remaining
What is the output of this Kotlin code with integer overflow?
Consider this Kotlin code snippet. What will it print?
Kotlin
fun main() {
    val maxInt = Int.MAX_VALUE
    val result = maxInt + 1
    println(result)
}
AOverflowException
B-2147483648
C2147483647
D2147483648
Attempts:
2 left
💡 Hint
Adding 1 to Int.MAX_VALUE causes integer overflow in Kotlin's Int type.