Lesson 5 Operators
Lesson 5 Operators
JAVA
LESSON 5
WHAT IS A JAVA OPERATOR?
EXAMPLES:
Operators Description
+ Addition – adds two operands
THEM.
• For example, != returns true if its two operands
are unequal. Relational operators are used to test
whether two values are equal, whether one value
is greater than another, and so forth.
Operator Description
== Checks if the values of two operands are equal or not, if yes the
condition becomes true.
!= Checks if the values of two operands are equal or not, if values are not
equal the condition becomes true.
> Checks if the value of the left operand is greater than the value of right
operand, if yes the condition becomes true.
< Checks if the value of left operand is less than the value of right
operand, if yes then condition becomes true.
>= Checks if the value of left operand is less than or equal to the value of
right operand, if yes then condition becomes true.
<= Checks if the value to left operand is less than or equal to the value of
right operand, if yes then condition becomes true.
EXAMPLE OF RELATIONAL OPERATORS:
public Less ThanExample
{
public static void main(String args[])
{
int a = 5;
int b = 10;
if(a<b)
{
System.out.println(“The Statement is true”);
}
}
}
3. CONDITIONAL/LOGICAL OPERATORS – THESE LOGICAL OPERATORS WORK ONLY ON
BOOLEAN OPERANDS. THEIR RETURN VALUES ARE ALWAYS BOOLEAN.