Page 346 - Computer_Science_F5
P. 346
Operator type Symbol Description Syntax example
Logical NOT ! The logical NOT operator is !(A&&B)
used to invert or reverse the
logical state of its operand. Chapter Five: Object oriented programming with Java
When a condition is true,
FOR ONLINE READING ONLY
applying the logical NOT
operator will result in the
condition becoming false
(e) Assignment operators “ =”
Table 5.12: Assignment Operators
Operator Description Example
= Assigns the value on the right to the int a = 5;
variable on the left.
+= Adds the value on the right to the variable a += 3; // a = a + 3
on the left and assigns the result to the
variable on the left.
-= Subtracts the value on the right from the a -= 2; // a = a - 2
variable on the left and assigns the result
to the variable on the left.
*= Multiplies the variable on the left by the a *= 4; // a = a * 4
value on the right and assigns the result to
the variable on the left.
/= Divides the variable on the left by the a /= 2; // a = a / 2
value on the right and assigns the result to
the variable on the left.
%= Calculates the remainder of the division of a %= 3; // a = a % 3
the variable on the left by the value on the
right and assigns the result to the variable
on the left.
&= Performs a bitwise AND operation on the a &= 1; // a = a & 1
variable on the left and the value on the
right and assigns the result to the variable
on the left.
337
Student’s Book Form Five
Computer Science Form 5.indd 337 23/07/2024 12:34

