What if your program could do all the math for you perfectly every time?
Why Arithmetic operators in Kotlin? - Purpose & Use Cases
Imagine you want to calculate the total cost of items you bought, but you have to do each addition, subtraction, multiplication, or division by hand every time.
Doing math manually is slow and easy to make mistakes. If you have many numbers, it becomes confusing and tiring to keep track of all calculations.
Arithmetic operators let the computer do all the math for you quickly and correctly. You just write simple expressions, and the computer calculates the results instantly.
val total = price1 + price2 + price3 val discount = total - 10 val finalPrice = discount * 0.9
val finalPrice = (price1 + price2 + price3 - 10) * 0.9
Arithmetic operators let you write clear, fast, and error-free math calculations in your programs.
Calculating the total bill at a restaurant including tax and tip without using a calculator.
Manual math is slow and error-prone.
Arithmetic operators automate calculations in code.
This makes programs faster and easier to write.