Assignment operators
Increment variable by right hand value:
int a = 4;
a = a + 2;
System.out.println("Value:" + a); |
int a = 4;
a += 2;
System.out.println("Value:" + a); |
Value:6 |
Logical and
operation:
boolean examSuccess = true,
registered = false;
examSuccess = examSuccess & registered;
System.out.println(
"Exam success:" + examSuccess); |
boolean examSuccess = true,
registered = false;
examSuccess &= registered;
System.out.println(
"Exam success:" + examSuccess); |
Exam success:false |
= |
Assign right to left operand |
+= |
Assign sum of operands to left operand |
-= |
Assign difference of operands to left operand |
*= |
Assign product of operands to left operand |
/= |
Assign quotient of operands to left operand |
%= |
Assign remainder of operands to left operand |
&= |
Assign logical “and” of operands to left operand |
|= |
Assign logical “or” of operands to left operand |
No. 51
Understanding +=
Q: |
Consider the following snippet:
This will compile and execute thereby incrementing the
On the other hand the
Tip |
||||
A: |
According to Figure 119, “No binary + operator yielding
NoteSince
On contrary the operator
Notice 24 being equal to |