Java Multiplication Assignment

In Java, Multiplication Assignment Operator is used to find the product of the value (right operand) and this variable (left operand) and assign the result back to this variable (left operand). In this tutorial, we will learn how to use Multiplication Assignment operator in Java, with examples.

The syntax to find the product of a value 2 with variable x and assign the result to x using Multiplication Assignment Operator is

x *= 2

Example

In the following example, we take a variable x with an initial value of 5, multiply it with a value of 2 and assign the result back to x, using Multiplication Assignment Operator.

Main.java

public class Main {
    public static void main(String[] args) {
        int x = 5;
        //multiplication assignment
        x *= 2;
        System.out.println("x : " + x);
    }
}

Output

x : 10
ADVERTISEMENT

Conclusion

In this Java Tutorial, we learned about Multiplication Assignment Operator in Java, with examples.