Arithmetic Expressions in Java:
We can use the Eclipse IDE for this example. If you do not know about it then follow this link- How to Install Eclipse For Java and create a program in it. |
Arithmetic Expressions in Java are used to perform arithmetic calculations. It consists of a series of operands separated by operators. An operand is the values, variables, numbers, or different quantities. Operators are arithmetic symbols i.e. addition (+), subtraction (-), multiplication (*), division ( \), and modulus (%). The modulus operator is used to find the remainder in the division.
- Addition ( + ) Operator:
- Subtraction ( – ) Operator:
- Multiplication ( * ) Operator:
- Division ( / ) Operator:
- Modulus ( % ) Operator:
- Increment Operator ( ++ ):
- Decrement Operator ( — ):
Note: When the two operands are integers and division is performed, the results are sometimes surprising. That is because the division of two integers always produces an integer result that is truncated and not rounded as shown below.
If we need a decimal value then we use double data type in java as shown below.
Comments (No)