Challenge - 5 Problems
Arithmetic Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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) }
Attempts:
2 left
💡 Hint
Remember that dividing two integers in Kotlin results in an integer division.
✗ Incorrect
In Kotlin, dividing two Int values uses integer division, so 10 / 3 equals 3, discarding the remainder.
❓ Predict Output
intermediate2: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) }
Attempts:
2 left
💡 Hint
When dividing an Int by a Double, Kotlin promotes the Int to Double.
✗ Incorrect
Since 'y' is a Double, 'x' is converted to Double and floating-point division is performed, resulting in 3.5.
❓ Predict Output
advanced2: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) }
Attempts:
2 left
💡 Hint
The modulus operator (%) gives the remainder after division.
✗ Incorrect
17 divided by 5 is 3 with a remainder of 2, so 17 % 5 equals 2.
❓ Predict Output
advanced2: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) }
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication before addition.
✗ Incorrect
3 * 2 equals 6, then n += 6 means n = 8 + 6 = 14.
❓ Predict Output
expert2: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) }
Attempts:
2 left
💡 Hint
Adding 1 to Int.MAX_VALUE causes integer overflow in Kotlin's Int type.
✗ Incorrect
Kotlin's Int type is a 32-bit signed integer. Adding 1 to the maximum value wraps around to the minimum value (-2147483648).