Java | Operators: Operators are used for performing calculations.
List of Operators:
Additional Operator: Add two values with this additional operator, it is denoted by '+'.
Ex: 100 + 1.
Subtraction Operator: Minus one value from another value with this operator, it is denoted by '-'.
Ex: 100 - 1.
Multiplication Operator: Multiply two values with this operator, it is denoted by '*'.
Ex: 100 * 1.
Division Operator: Divide one value from another value with this operator, it is denoted by '/'.
Ex: 100 / 1.
Modulo Operator: Remainder of dividing one value with another value, it is denoted by '%'.
Here is the Code:
- import java.io.*;
- class Main {
- public static void main (String[] args) {
- // Addition
- System.out.println(1 + 2);
- // Subtraction
- System.out.println(2 - 1);
- // Multiplication
- System.out.println(1 * 2);
- // Divition
- System.out.println(1F / 2F);
- // Modulo
- System.out.println(1 % 2);
- }
- }
Output:
3
1
2
0.5
1
Here is the Video: