Arithmetic operators are symbols that perform basic math operations like addition, subtraction, multiplication, division, and modulus on numbers.
Click to reveal answer
beginner
What does the '+' operator do in Kotlin?
The '+' operator adds two numbers together. For example, 3 + 2 equals 5.
Click to reveal answer
beginner
What is the result of 10 % 3 in Kotlin?
The '%' operator gives the remainder of division. 10 % 3 equals 1 because 3 goes into 10 three times with 1 left over.
Click to reveal answer
intermediate
How does Kotlin handle division with '/' operator for integers?
When dividing two integers, Kotlin performs integer division, which means it returns the whole number part only, discarding any remainder.
Click to reveal answer
beginner
What is the difference between '/' and '%' operators in Kotlin?
'/' divides two numbers and returns the quotient, while '%' returns the remainder after division.
Click to reveal answer
What is the result of 7 + 5 in Kotlin?
A2
B12
C75
DError
✗ Incorrect
7 + 5 adds the two numbers to get 12.
What does the '%' operator do?
AReturns the remainder of division
BDivides two numbers
CMultiplies two numbers
DSubtracts two numbers
✗ Incorrect
The '%' operator returns the remainder after dividing two numbers.
What is the output of 10 / 4 in Kotlin when both are integers?
A2
B2.5
C3
D4
✗ Incorrect
Integer division discards the decimal part, so 10 / 4 equals 2.
Which operator multiplies two numbers?
A+
B-
C/
D*
✗ Incorrect
The '*' operator multiplies two numbers.
What is the result of 15 % 6?
A2
B0
C3
D9
✗ Incorrect
15 divided by 6 is 2 with a remainder of 3, so 15 % 6 equals 3.
Explain the five basic arithmetic operators in Kotlin and give an example of each.
Think about +, -, *, /, and % symbols.
You got /6 concepts.
Describe how Kotlin handles division when both numbers are integers.
What happens to the decimal part?
You got /3 concepts.
Practice
(1/5)
1. Which arithmetic operator in Kotlin is used to find the remainder of a division?
easy
A. The / operator
B. The % operator
C. The * operator
D. The - operator
Solution
Step 1: Understand the meaning of each operator
The % operator gives the remainder after division, / divides, * multiplies, and - subtracts.
Step 2: Identify the operator for remainder
The % operator is specifically for remainder calculation in Kotlin.
Final Answer:
The % operator -> Option B
Quick Check:
Remainder operator = % [OK]
Hint: Remember % means remainder in math and Kotlin [OK]
Common Mistakes:
Confusing / with %, thinking / gives remainder
Using * or - for remainder
Mixing up operators with similar symbols
2. Which of the following is the correct way to write a multiplication operation in Kotlin?
easy
A. val result = 5 x 3
B. val result = 5 . 3
C. val result = 5 / 3
D. val result = 5 * 3
Solution
Step 1: Recall Kotlin syntax for multiplication
Kotlin uses * for multiplication, not x or dot.
Step 2: Check each option
val result = 5 * 3 uses * correctly; others are invalid syntax or different operations.
Final Answer:
val result = 5 * 3 -> Option D
Quick Check:
Multiplication operator = * [OK]
Hint: Use * for multiplication, not x or dot [OK]
Common Mistakes:
Using x instead of *
Using dot for multiplication
Confusing division / with multiplication
3. What is the output of the following Kotlin code?
val a = 10
val b = 3
println(a / b)
medium
A. 3
B. 3.3333333
C. 3.0
D. Error
Solution
Step 1: Identify variable types and operation
a and b are integers, so a / b does integer division.
Step 2: Calculate integer division result
10 divided by 3 is 3.333..., but integer division drops decimals, so result is 3.
Final Answer:
3 -> Option A
Quick Check:
Integer division drops decimals = 3 [OK]
Hint: Integer division drops decimals; result is integer [OK]
Common Mistakes:
Expecting decimal result with integer division
Confusing / with floating-point division
Thinking output is 3.0 or error
4. The following Kotlin code has an error. What is the problem?
val x = 7
val y = 2
val result = x / y.toDouble()
println(result)
medium
A. Cannot call toDouble() on y
B. Division operator / cannot mix Int and Double
C. No error, code runs and prints 3.5
D. Missing explicit type declaration for result
Solution
Step 1: Analyze the types involved in division
y.toDouble() converts y to Double, so x / y.toDouble() divides Int by Double.
Step 2: Check Kotlin's handling of mixed numeric types
Kotlin automatically converts Int to Double for mixed operations, so no error occurs.
Final Answer:
No error, code runs and prints 3.5 -> Option C
Quick Check:
Mixed Int/Double division allowed = 3.5 [OK]
Hint: Kotlin auto-converts Int to Double in mixed division [OK]
Common Mistakes:
Thinking toDouble() causes error
Believing mixed types cause syntax error
Expecting need for explicit type declaration
5. You want to calculate the average of three large integer scores (e.g., 1000000000 each) in Kotlin and get a precise decimal result. Which code snippet correctly does this?
hard
A. val avg = (score1.toDouble() + score2.toDouble() + score3.toDouble()) / 3
B. val avg = (score1 + score2 + score3) / 3.0
C. val avg = (score1 + score2 + score3).toDouble() / 3
D. val avg = (score1 + score2 + score3) / 3
Solution
Step 1: Understand integer division problem
Dividing integers by integer 3 causes integer division, losing decimals.
Step 2: Convert all scores to Double before division
Converting each score to Double ensures floating-point division and precise average.
Step 3: Check each option
val avg = (score1.toDouble() + score2.toDouble() + score3.toDouble()) / 3 converts all scores to Double before adding and dividing, giving correct decimal average.
Final Answer:
val avg = (score1.toDouble() + score2.toDouble() + score3.toDouble()) / 3 -> Option A
Quick Check:
Convert all to Double before division for decimal average [OK]
Hint: Convert all integers to Double before dividing for decimals [OK]