The following code sample prints 1.5.
float a = 3;
float b = 2;
a /= b;
System.out.println(a);
I don't understand what the /= operator does. What is it supposed to represent?
It's a combination division-plus-assignment operator.
a /= b;
means divide a by b and put the result in a.
There are similar operators for addition, subtraction, and multiplication: +=, -= and *=.
%= will do modulus.
>>= and <<= will do bit shifting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With