Java Division Assignment

In Java, Division Assignment Operator is used to find the division of the variable (left operand) by a value (right operand) and assign the resulting quotient to this variable (left operand).

In this tutorial, we will learn how to use Division 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 Division Assignment Operator is

</>
Copy
x /= 2

Example

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

Main.java

</>
Copy
public class Main {
    public static void main(String[] args) {
        int x = 9;
        //division assignment
        x /= 2;
        System.out.println("x : " + x);
    }
}

Output

x : 4

Conclusion

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