Arithmetic operators
- In Java arithmetic operators are used in mathematical calculations.
- Arithmetic operators are used in the same way as they are used in algebra.
- These can be used with both integers and floating-point values.
- Following are the list of arithmetic operators in java.
Operator | Function |
---|---|
+ | Addition |
– | Subtraction |
* | Multiplication |
/ | Division |
% | Remainder |
int sum = 1 + 2;
int difference = 6 - 3;
int product = 2 * 3;
int quotient = 4 / 2;
int remainder = 7 % 2;
- Addition operator (+) is used to add values or variable.
- Subtraction operator (-) is used to get the difference of values or variables.
- Multiplication operator (*) is used to get the product of values or variables.
- Division operator (/) is used to divide values or variables.
- Reminder operator (%) is used to get the remainder of a value or a variable if it is divided from the other value or the variable.
Which arithmetic operator can be used to find the remainder when a variable divided by a number.