Page 98 - 2617_JSSPS_C-6
P. 98
Relational Operators
Relational operators help to compare quantities and return the Boolean value ‘True’ or ‘False’ as a
result. These are also known as comparison operators.
Example
Operator Description Syntax Output
(int a = 11, b = 4)
== This operator is used to check the (a == b) a == b false
Equal to equality between two values. a == 11 true
!= This operator is used to check the (a != b) a != b true
Not Equal to inequality between two values. a != 11 false
> This operator checks if the first value is (a > b) (a > b) true
Greater than greater than the second value. (11 > 13) false
< This operator is used to check if the first (a < b) (a < b) false
Less than value is less than the second value. (15 < 20) true
>= This operator is used to check if the (a >= b) (a >= b) true
greater than first value is greater than or equal to (22 >= 22) true
or equal the second value. (21 >= 23) false
<= This operator is used to check if the (a <= b) (a <= b) false
less than or first value is less than or equal to the (30 <= 31) true
equal to second value. (27 <= 27) true
Logical Operators
Logical operators are used to combine multiple conditions and evaluate them. They return a Boolean
value ‘True’ or ‘False’ as result.
Operator Description Syntax Example Output
&& (AND) Returns ‘true’ value if all the given (a>b) && (b>c) (11 > 4) && (4 > 15) false
conditions are true. (11 > 4) && (15 > 4) true
|| (OR) Returns ‘true’ value if any one of the (a>b) || (b>c) (11 > 4) || (4 > 15) true
given conditions is true. (11 > 4) || (15 > 4) true
(4 > 11) || (4 > 15) false
NOT (!) Returns ‘true’ value if the condition ! (a > b) !(11 > 4) false
returns false and vice-versa. !(4 > 11) true
Unary Operators
Unary operators are special operators that require only one operand or value to perform operations.
Increment and decrement are the examples of unary operators.
Example
Operator Description Syntax Output
(int a = 11, b = 0)
++ Returns the incremented value as result. a ++ b = a++ a=12 b=11
increment
-- Returns the decremented value as result. a -- b = a-- a=10 b=11
decrement
96 Premium Edition-VI

