In Java, the expression q -= r
is a compound assignment operator, which subtracts the value of r
from q
and assigns the result back to q
. It is equivalent to the expression q = q - r
.
If q
is initially some numeric value and r
is another numeric value, the result of the expression q -= r
would be:
q = q - r;
Here's an example in Java:
public class CompoundAssignmentExample {
public static void main(String[] args) {
// Declare variables
int q = 8;
int r = 3;
// Compound assignment
q -= r;
// Display the result
System.out.println("The value of q after q -= r is: " + q);
}
}
In this example, if q
is initially 8
and r
is 3
, after the operation, the value of q
will be 5
(8 - 3).