The operand on the left side of the assignment operator must be a variable, not a constant or an expression. The value of the assignment expression is = the value of the variable on the left side.
Notice:
1) Do not confuse the assignment operator = with the relational operator ==.
2) In addition to the assignment operator =, there is also an extended assignment operator.
Example:
publicclassMain{publicstaticvoidmain(String[]args){inta=1;intb=2;intc=0;c=a+b;System.out.println(c=a+b=+c);c+=a;Sy stem.out.println(c+=a=+c);c-=a;System.out.println(c-=a=+c);c*=a;System.out.println(c*=a= +c);a=3;c=4;c/=a;System.out .println(c/=a=+c);a=5;c=6;c%=a;System.out.println(c%=a=+c);c&=a;System.out.println( c&=a=+c);c|=a;System.out.println (c|=a=+c);c^=a;System.out.println(c^=a=+c);c>>=1;System.out.println(c>>=1=+c );c<<=1;System.out.println(c<<=1=+c);}}
The running results are as follows:
c=a+b=3c+=a=4c-=a=3c*=a=3c/=a=1c%=a=1c&=a=1c|=a=5c^=a=0c>>=1= 0c<<=1=0