Last Updated: 28 May, 2022
Operators are special symbols that perform the specified operations. Each operator is responsible to perform some specific operation on variables or values and return a result. The operators are classified and listed according to precedence order.
Java supports the following types of operators:
An Assignment Operator is an operator used to assign a new value to a variable. The assignment operator assigns a value from the right side operand or value to the left side operand.
For example, int year = 2022; here, = is an assignment operator. It assigns the '2022' value to its left side operand 'year'.
Java has provided the following types of assignment operators, see the given table below.
| Operator | Description | Example | Equivalent to |
|---|---|---|---|
| = | Assigns value from right side operand to left side operand | z = y | z = y |
| += | It adds right operand to the left operand and assigns the result to left operand | x += y | x = x + y |
| -= | It subtracts right operand from the left operand and assigns the result to left operand | x -= y | x = x - y |
| *= | It multiplies right operand with the left operand and assigns the result to left operand | x *= y | x = x * y |
| /= | It divides left operand with the right operand and assigns the result to left operand | x /= y | x = x / y |
| %= | It takes modulus using two operands and assigns the result to left operand | x %= y | x = x % y |
| ^= | Performs exponential (power) calculation on operators and assign value to the left operand | x ^= y | x = x ^ y |
Let's understand the assignment operators with the help of an example.
Example: Assignment Operators uses in the Java Program
Output
10
30
20
200
20
0
10
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com