| Operator | Description | Example | Concept |
|---|---|---|---|
+ |
Addition | a + b |
Adds the values of a and b. |
- |
Subtraction | a - b |
Subtracts the value of b from a. |
* |
Multiplication | a * b |
Multiplies the values of a and b. |
/ |
Division | a / b |
Divides the value of a by b. |
% |
Modulus | a % b |
Returns the remainder of the division a / b. |
++ |
Increment | a++ or ++a |
Increases the value of a by 1. |
-- |
Decrement | a-- or --a |
Decreases the value of a by 1. |
Relational operators are used to compare values and determine the relationship between them. They return a boolean result (true or false) based on the outcome of the comparison.
| Operator | Description | Example | Result |
|---|---|---|---|
< |
Less than | a < b |
true if a is less than b, false otherwise. |
> |
Greater than | a > b |
true if a is greater than b, false otherwise. |
<= |
Less than or equal to | a <= b |
true if a is less than or equal to b, false otherwise. |
>= |
Greater than or equal to | a >= b |
true if a is greater than or equal to b, false otherwise. |
| Operator | Description | Example | Result |
|---|---|---|---|
== |
Equal to | a == b |
true if a is equal to b, false otherwise. |
!= |
Not equal to | a != b |
true if a is not equal to b, false otherwise. |
These operators are used to compare values in conditional statements, loops, and other control structures in Java programs. They return a boolean result (true or false) based on the outcome of the comparison.
These operators are used to perform logical operations in Java. They are commonly used in conditional statements, loops, and other situations where decision-making based on boolean conditions is required.
| Operator | Description | Example | Result |
|---|---|---|---|
&& |
Logical AND | a && b |
true if both a and b are true, false otherwise. |
| **` | `** | Logical OR | |
! |
Logical NOT | !a |
true if a is false, false if a is true. |
? :)**result = (condition) ? valueIfTrue : valueIfFalse;**
Example:
int x = 5;
int y = 10;
int max = (x > y) ? x : y;
In this example, max will be assigned the value of x if x is greater than y, and the value of y otherwise.