Operators (Part 7)

Java Operators

Operators are used to perform operations on variables and values.

In the example below, we use the + operator to add together two values:

Eg:-

  public class MyClass {   
   public static void main(String []args) {   
   int num1=5;   
   int num2=10;   
   int sum;   
   sum=num1+num2;   
    System.out.println(sum); //prints 15  
   }   
  }

Also the + operator can also be used to concatenate strings or supply value:

System.out.println("Addition is:"+sum);

Output:-

 Addition is:15  


Java divides the operators into the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Bitwise operators




< Previous Next >