Compound Assignment Operator in JavaIn Java, assignment operator is used to assign values to a variable. In this section, we will discuss the compound assignment operators in Java. Compound Assignment OperatorThe compound assignment operator is the combination of more than one operator. It includes an assignment operator and arithmetic operator or bitwise operator. The specified operation is performed between the right operand and the left operand and the resultant assigned to the left operand. Generally, these operators are used to assign results in shorter syntax forms. In short, the compound assignment operator can be used in place of an assignment operator. For example: Let's write the above statements using the compound assignment operator. Using both assignment operators generates the same result. Java supports the following assignment operators:
Using Compound Assignment Operator in a Java ProgramCompoundAssignmentOperator.java Output: z = x + y = 38 z += x = 63 z -= x = 38 z *= x = 950 z /= x = 0 z %= x = 5 z <<= 2 = 10 z >>= 2 = 5 z >>= 2 = 2 z &= x = 0 z ^= x = 12 z |= x = 12 s>>>= 4 = 18 Next TopicPrime Points in Java |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India