JAVA programs

Java Program Using Compound assignment operator

In this program we see the use of the Compound assignment operator like 
+= (compound addition assignment operator) 
/= (compound division assignment operator)
%= (compound modulo assignment operator)
-=  (compound subtraction assignment operator)
*= (compound multiplication assignment operator)
&= (compound Bitwise & assignment operator)


//Program Using Compound assignment operator

class CompAssignDemo


    public static void main(String[] args)


        int x=5;

        int y=10;


        System.out.println("The addition is:"+x);


        System.out.println("The substraction is:"+x);


        System.out.println("The multiplication is:"+x);


        System.out.println("The division is:"+x);


        System.out.println("The remainder is:"+x);


        System.out.println("The result of AND operation:"+x);


        System.out.println("The result of Bitwise inclusive OR operation:"+x);


        System.out.println("The result signed LEFT shift operation:"+x);   



When Run The Program Following Output:

The addition is:15

The substraction is:5

The multiplication is:50

The division is:5

The remainder is:5

The result of AND operation:0

The result of Bitwise inclusive OR operation:10

The result signed LEFT shift operation:10240


Compound assignment operator provides a shorter syntax for assigning the result of an arithmetic or bitwise operator that is useful for reduce the code and perform desire operation. They perform the operation on the two operands before assigning the result to the first operand. That means the operation performs between two operands and result save in first operand so we doesn’t have need to use third variable, That save memory space.

Releted Programs

© 2017 codewmAll rights reserved.