Science, Tech, Math › Computer Science Compound-Assignment Operators Print Atanas Bezov/E+/Getty Images Computer Science Java Programming PHP Programming Perl Python Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Paul Leahy Paul Leahy Computer Science Expert M.A., Advanced Information Systems, University of Glasgow Paul Leahy is a computer programmer with over a decade of experience working in the IT industry, as both an in-house and vendor-based developer. Learn about our Editorial Process Updated on July 15, 2018 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: Read More Conditional Operators By Paul Leahy += 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; Cite this Article Format mla apa chicago Your Citation Leahy, Paul. "Compound-Assignment Operators." ThoughtCo, Feb. 16, 2021, thoughtco.com/compound-assignment-operator-2034054. Leahy, Paul. (2021, February 16). Compound-Assignment Operators. Retrieved from https://www.thoughtco.com/compound-assignment-operator-2034054 Leahy, Paul. "Compound-Assignment Operators." ThoughtCo. https://www.thoughtco.com/compound-assignment-operator-2034054 (accessed April 25, 2024). copy citation