How To Use Java Operator With Examples

How To Use Java Operator With Examples
How To Use Java Operator With Examples

    Operator in java with examples

    Java Operator: A java operator can be used in mathematical operations perform.

    it is performed by java operands mathematical symbols like (+),(-),(*),(/), etc.


    Types of Java operators

    1. Arithmetic Operator


    2. Relational Operator


    3. Logical Operator 


    4. Assignment operator


    5. Bitwise Operator


    6. Increment operator


    7. Decrement Operator


    8. Conditional Operator


    Arithmetic operator in Java Language


    Arithmetic Operator: A arithmetic operation is a used mathematical operation performed.

    It is many operations performed like additionsubtraction, multiplication, and division.

    Important Same Others Languages Operator

    👉C++ Operators 

    👉C Operators 

    👉 Python Operators


    Example of Arithmetic operator

    Addition:a+b or 10+10=20
    Here a is operands value (+) Addition is operator and b is operands. It can be used for additional operations performed.

    Subtraction:a-b or 20-10=10
    Here a is operands value (-) Subtraction sign is operator and b is operands. It can be used as Subtraction operations performed.

    Multiplication:a*b or 10*10=100
    Here a is operands value (*) Multiplication sign is operator and b is operands. It can be used Multiplication operations performed.

    Division:a/b or 10/5=2
    Here a is operands value (/) Division sign operator and b is operands. It can be used for Division operations performed.

    Modules: a%b or 10%3=1
    Here a is operands value (%) Modules sign operator and b is operands. It can be used Modules operations performed.

    Java Arithmetic Operator Table

    Sign.           Operation.         Example


    (+)              Addition                    (a+b)


    (-)               Subtraction              (a-b)  

     
    (*)              Multiplication         (a*b)


    (/)               Division                     (a/b)


    (%)            Modules                    (a%b)



    How To Use Arithmetic Operator in Java?

    class icoderweb


    {


    public static void main(String[] args()


    {


    int a=35


    int b=6;


    System.out.println("Addition:"+(a+b));

    System.out.println("Subtraction:"+(a-b));

    System.out.println("Multiplication:"+(a*b));

    System.out.println("Division:"+(a/b));


    System.out.println("Modulus:"+(a%b));


    }


    } 


    *****OUTPUT*****


    Addition:41


    Subtraction:29


    Multiplication:210


    Division:5.8333333


    Modulus:5


    Relational Operator in Java Language

    Relational Operator: A Java Relational operator has used the comparison of the two operands. It can be using equal operands and condition check in this operator. Relational operator very most and useful operator.

    Java Relational Operator Table

    Sign.      Operation.         Example


    (==)           Equal To              (a+b)


    (!=)           Not 
    Equal To       (a-b)   


    (>)            Greater Than       (a*b)


    (<)             Less Than           (a/b)


    (>=)   Grater than Or Equal  (a%b)


    (<=)   Less Than Or  Equal    (a%b)



    How To Use Relational Operator in Java? 

    class icoderweb


    {


    public static void main(String[] args()


    {


    int a=10;


    int b=10;


    if(a==b)


    {


    System.out.println("value of a and b are equal");


    }


    if(a!=100)


    {


    System.out.println("value not equal to");


    }


    if(a>5)


    {


    System.out.println("value a is grater than 5");


    }


    if(a<50)


    {


    System.out.println("value a is less than 50");


    }


    if(a>=10)


    {


    System.out.println("value a is grater than or equal to 10");


    }


    if(a<=10)


    {


    System.out.println("value a is less than or equal to 10");


    }


    }


    *****OUTPUT*****


    value of a and b are equal


    value not equal to


    value a is greater than 5


    value a is less than 50


    value a is greater than or equal to 10


    value a is less than or equal to 10



    Logical Operator in Java Language

    Java Logical Operators: Java Language provides three logical operators. logical Operator tests more than one condition to make decisions.


    Types of Java Logical Operator

    1.&& AND

    2.|| OR

    3.!  NOT

    1. AND Operator can be used decisions are two values.AND Operator two values are True AND Operator return True.

    But two values are anyone False AND Operator return False.

    2. OR operator performs a logical condition on two expressions. if or Operator can be two expressions are True OR Operator return true.
    But any of the expressions are False OR Operator return True.

    3. NOT operator is very easy Operator. it can be used condition are True NOT Operator returns False and condition are False NOT Operator returns True.

    How To Use Logical Operator in Java?

    class icoderweb


    {


    public static void main(String[] args()


    {


    int x=10;


    int y=60;


    int z=40;


    if(x>y&&x>z)


    System.out.println("x is grater");

    if(y>x&&y>z)

    System.out.println("y is grater");


    if(z>x&&z>y)


    } 


    }


    *****OUTPUT*****


    y is grater


    Java Assignment Operator Table 

    Sign.        Operation        Example


    (=)            a=b                         (a=b)


    (+=)        a+=b                      (a=a+b)   


    (-=)         a-=b                       (a=a-b)


    (*=)        a*=b                      (a=a*b)


    (/=)         a/=b                      (a=a/b)


    (%=)          a%=b                   (a=a%b)



    How To Use Assignment Operator in Java?

    class icoderweb


    {


    public static void main(String[] args()


    {


    int a=10,b=5;


    a+=b;


    System.out.println("Assignment Addition:"+a);


    int a1=10,b1=5;


    a1-=b1;


    System.out.println("Assignment Subtraction:"+a1);


    int a2=10,b2=5;


    a2*=b2;


    System.out.println("Assignment multiplication:"+a2);


    int a3=10,b3=5;


    a3/=b3;


    System.out.println("Assignment Division:"+a3);


    int a4=10,b4=5;


    a4%=b4;


    System.out.println("Assignment Division:"+a4);


    }


    }


    *****OUTPUT*****


    Assignment Addition:15


    Assignment Subtraction:5


    Assignment Multiplication:50


    Assignment Division:2


    Assignment Moduls:1



    Increment Operator in  Java Language

    Increment Operators :Increment Operators are useful operators generally used.like++x and x++ means x=x+1.
    pre-increment first add one to the operand and then the result is assigned to the variable on the left.
    post-increment first assigns the value to the variable on the 
    left and then increments the operand.

    How To Use Increment Operator in Java?

    class icoderweb


    {


    public static void main(String[] args()


    {

    int a=5;

    int b=10;

    System.out.println("pre-increment operator:+(++a));

    System.out.println("post-increment operator:+(b+1));

    }

    }

    *****OUTPUT*****


    pre-increment operator:6


    post-increment operator:11



    Decrement Operator in  Java Language

    Java Decrement: A Decrement Operator used the decrease the value. like --x and x--.
    Pre-decrement first less one to the operands and then the result is assigned to the variable on the left.

    Post-decrement first assigns the value to the variables on the left and then decrements the operands.


    How To Use Decrement Operator in Java?

    class icoderweb


    {


    public static void main(String[] args()


    {

    int a=5;

    int b=10;

    System.out.println("pre-decrement operator:+(--a));

    System.out.println("post-decrement operator:+(b-1));

    }

    *****OUTPUT*****

    pre-decrement operator:4


    post-decrement operator:9



    Bitwise Operator in  Java Language

    Java Bitwise Operator: A Bitwise operator is an operation performed on the data bit level. the bitwise operator is also shifted bit right to left.

    Note: Bitwise operators are not allowed to float and double.

    Java Bitwise Operator Table 

    Sign.        Operation.         Example


    (&)           Bitwise AND         (a&b)


    (|)             Bitwise OR             (a|b)  

     
    (<<)         Bitwise LEFT        (a<<2)


    (>>)        Bitwise RIGHT      (a>>2)


    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.