Friday, May 15, 2020

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;

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.