Multiply Assign Operator

The multiply assign operator does two operations in one statement. First is that it multiplies the value of a variable on the left side with the evaluated value of the expression on the right side. The result is assigned back to the variable. This is why it is called a compounded assign operator is because it is a short hand for two operations. Below are examples on Multiply Assign Operator in Java.

Multiply Assign With Literal

The symbol that Java provides to perform a Multiply Assign Operator is *=, which is intuitive because asterisk is the symbol for multiplication while equal symbol is the symbol for assignment - hence multiply assign. the most basic example we can think of is to multiple assign a literal value to a variable, see below:
int a = 4;
a *= 5;
The value of a is multiplied by 5 which results to 20. That value is assigned back to the variable a. Hence the two part operation is done in one statement and will have below output:

Multiply Assign With Another variable

Another example is to multiply a variable with the value of another variable. This is possible and an example is shown below:

int a = 6;
int b = 4;
a *= b;

So a is multiplied by b, which is just 6 times 4, that equals to 24. The value of 24 is assigned not to b, but to a, because a is on the left side. So the variable a has the value shown below by the output:

Multiply Assign With An Expression

And we are not limited to literal or variable on the right side of the multiply assign operator, we can actually have an expression on the right. See below:
int a = 7;
int b = 2;
a *= b * 3;
So b is multiplied by 3, which is just 2 times 3 equals 6. The value 6 is multiplied to a, which is 6 times 7 equals 42. The final answer is assigned to variable a, hence we get belo9w: