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.