0% completed
Arithmetic operators perform basic mathematical operations such as addition, subtraction, multiplication, division, and modulus. They are used in expressions to compute values and manipulate numerical data.
Below is a table summarizing the arithmetic operators available in Java:
Operator | Symbol | Operation |
---|---|---|
Addition | + | Adds two operands |
Subtraction | - | Subtracts the right operand from the left |
Multiplication | * | Multiplies both operands |
Division | / | Divides the numerator by the denominator |
Modulus | % | Returns the remainder after division |
Below is a simple example that demonstrates basic arithmetic operations.
Explanation:
Below is an example that uses arithmetic operators in a combined expression to calculate a result.
Explanation:
x
, y
, and z
are defined with values 20
, 3
, and 5
.x + y * z - x / y
, arithmetic operators are combined.result
and printed.(x + y) % z
first adds x
and y
due to the parentheses, then applies the modulus operator %
with z
.modResult
and printed.These examples demonstrate how arithmetic operators work in Java to perform calculations and combine numerical values within expressions.
.....
.....
.....