











Java: Arithmetic Operators


Operators
Java provides quite a variety of operators which come in handy to the programmer for the manipulation of variables.
The operators in java are as follows:
- Arithmetic Operators
- Relational Operators
- Bitwise Operators
- Logical Operators
- Assignment Operators
- Miscellaneous Operators
Arithmetic Operators
They are used in mathematical expressions in the same way that they are used in algebra, i.e, to perform the basic mathematical functions.
These operators perform the most simple calculations and are five in number as shown in the table.
Operator | Functionality | Syntax |
+ | Addition | a+b |
– | Subtraction | a-b |
* | Multiplication | a*b |
/ | Division | a/b |
% | Modulus | a%b |


Syntax with Example
Run
class Main { public static void main(String[] args) { // declare variables int a = 26, b = 4; // addition operator System.out.println("a + b = " + (a + b)); // subtraction operator System.out.println("a - b = " + (a - b)); // multiplication operator System.out.println("a * b = " + (a * b)); // division operator System.out.println("a / b = " + (a / b)); // modulo operator System.out.println("a % b = " + (a % b)); } }
Output
a + b = 30 a - b = 22 a * b = 104 a / b = 6 a % b = 2
Login/Signup to comment