Monday, December 30, 2019
What Is a Compound-Assignment Operator
Compound-assignment operators provide a shorter syntax for assigning the result of an arithmetic or bitwise operator. They perform the operation on the two operands before assigning the result to the first operand. Compound-Assignment Operators in Java Java supports 11 compound-assignment operators: Ã Ã Ã assigns the result of the addition. -Ã Ã Ã assigns the result of the subtraction. *Ã Ã Ã assigns the result of the multiplication /Ã Ã Ã assigns the result of the division. %Ã Ã Ã assigns the remainder of the division. Ã Ã assigns the result of the logical AND. |Ã Ã Ã assigns the result of the logical OR. ^Ã Ã Ã assigns the result of the logical XOR. Ã Ã assigns the result of the signed left bit shift. Ã Ã assigns the result of the signed right bit shift. Ã assigns the result of the unsigned right bit shift. Example Usage To assign the result of an addition operation to a variable using the standard syntax: //add 2 to the value of number number number 2; But use a compound-assignment operator to effect the same outcome with the simpler syntax: //add 2 to the value of number number 2;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.