Module 3: Operators, Expressions, and Strings
Arithmetic and Assignment Operators
Use `+`, `-`, `*`, `/`, `%`, and assignment operators to update values and calculate results.
Author
Java Learner Editorial Team
Reviewer
Technical review by Java Learner
Last reviewed
2026-04-16
Java version
Java 25 LTS
Learning goals
- Use the main arithmetic operators correctly
- Update variables with assignment
- Read short math expressions in Java
Arithmetic operators: Use +, -, *, /, and % for addition, subtraction, multiplication, division, and remainder.
Assignment operators: = stores a value in a variable. Variants such as += and -= update the variable using its current value.
Integer division warning: 7 / 2 with integers gives 3, not 3.5. Use a double if you need decimal precision.
Why this matters: Most beginner projects use arithmetic long before they use classes or frameworks.
Runnable examples
Basic arithmetic
public class Main {
public static void main(String[] args) {
int a = 10;
int b = 3;
System.out.println(a + b);
System.out.println(a % b);
}
}Expected output
13 1
Update with assignment
public class Main {
public static void main(String[] args) {
int score = 10;
score += 5;
score -= 2;
System.out.println(score);
}
}Expected output
13
Common mistakes
Expecting integer division to keep decimals
Use a `double` value in the expression if you need decimal results.
Mini exercise
Create a price variable, add tax to it with `+=`, and print the final value.
Summary
- Arithmetic changes values.
- Assignment stores or updates values.
- Integer division behaves differently from decimal division.
Next step
Next, compare values and combine conditions with logical operators.
Sources used