Notifications
Clear all
Topic starter 01/08/2025 11:56 pm
Let’s decode Java operators together—it’s like teaching your code how to do math, logic, and comparisons 🧠✨
➕ Arithmetic Operators
These handle basic math:
Operator | Meaning | Example | Result |
---|---|---|---|
+ |
Addition | 5 + 3 |
8 |
- |
Subtraction | 5 - 3 |
2 |
* |
Multiplication | 5 * 3 |
15 |
/ |
Division | 6 / 3 |
2 |
% |
Modulus | 7 % 3 |
1 (remainder) |
🔍 Relational/Comparison Operators
Used to compare two values—returns true
or false
:
Operator | Meaning | Example |
---|---|---|
== |
Equal to | 5 == 5 → true |
!= |
Not equal to | 5 != 3 → true |
> |
Greater than | 5 > 3 → true |
< |
Less than | 3 < 5 → true |
>= |
Greater or equal | 5 >= 5 → true |
<= |
Less or equal | 3 <= 5 → true |
🤖 Logical Operators
Used for combining boolean conditions:
Operator | Meaning | Example | Result | ||||
---|---|---|---|---|---|---|---|
&& |
AND | true && false |
false |
||||
` | ` | OR | `true | false` | true |
||
! |
NOT | !true |
false |
🧪 Assignment Operators
Used to assign values:
Operator | Meaning | Example |
---|---|---|
= |
Assign | x = 5 |
+= |
Add then assign | x += 2 (same as x = x + 2 ) |
-= |
Subtract then assign | x -= 2 |
*= |
Multiply then assign | x *= 2 |
/= |
Divide then assign | x /= 2 |
%= |
Modulus then assign | x %= 2 |
✨ Bonus: Unary Operators
They work on a single operand:
++x
orx++
: Increment by 1--x
orx--
: Decrement by 1+x
: Positive (rarely used)-x
: Negation