Skip to main content

Operators

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:

  1. import java.io.*;

  2. class Main {
  3. public static void main (String[] args) {
  4.     // Addition
  5.     System.out.println(1 + 2);
  6.     // Subtraction
  7. System.out.println(2 - 1);
  8. // Multiplication
  9. System.out.println(1 * 2);
  10. // Divition
  11. System.out.println(1F / 2F);
  12. // Modulo
  13. System.out.println(1 % 2);
  14. }
  15. }

Output:
3
1
2
0.5
1

Here is the Video: