Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the /= operator in Java?

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?

like image 848
Austin Avatar asked Dec 04 '12 03:12

Austin


1 Answers

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.

like image 107
ccleve Avatar answered Oct 20 '22 18:10

ccleve