Java : Assignment Operators


Assignment Operator also called as op= operators and it’s used to reduce the expression size.

Following is the list of complete op= operators



+=
-=
*=
/=
%=
<>=
>>>=
&=
|=
^= 

See Also :

For Example : count +=2 has the will return the same result as expression statement : count = count + 2 ;

public class TestClass {

  public static void main(String[] arg) {
    int count1 = 5 , count2 = 5;

	//Calculation with assignment operator
    count1 += 2;
    System.out.println(count1);
    //equivalent matematical operation
    count2 = count2 + 2;
    System.out.println(count2);
  }
}

Output


7
7
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s