Relational and Logical Operators.

In this article, Relational and Logical Operators are explained in detail with examples. We will come to know about the Relational  and logical operators,truth table values for Logic AND, Logic OR and Logic NOT with examples provided.
They are also known as comparison operators because they compare two values and give the output as True/False. The operators are, (From topic Relational and Logical Operators)

Symbol
Description
Example
Less than
a<b
Greater than
a>b
<=
Less than or equal to
a<=b
>=
Greater than or equal to
a>=b
==
Equal to
a==b
!=
Not equal to
a!=b
Ex:
//Program related to Relational and Logical Operators..
class RelationalOperators
{
public static void main(String args[])
{
int x=5,y=8;
System.out.println("x is : "+x);
System.out.println("y is : "+y);
System.out.println("x<y is : "+(x<y));
System.out.println("x>y is : "+(x>y));
System.out.println("x<=y is : "+(x<=y));
System.out.println("x>=y is : "+(x>=y));
System.out.println("x==y is : "+(x==y));
System.out.println("x!=y is : "+(x!=y));
}
}
Output
x is : 5
y is : 8
x<y is : true
x>y is : false
x<=y is : true
x>=y is : false
x==y is : false
x!=y is : true
Relational Operator output-javaform
                           To get the code file use me.

These operators (Relational and Logical Operators) are used to perform compound condition evaluations.It checks for two or more conditions and gives the results as True/False.
The operators are,       (From topic Relational and Logical Operators)
  • Logical AND (&&) If given both the operands are non-zero, then the condition becomes true.
  • Logical OR    (||) If given any of the two operands are non-zero, then the condition becomes true.
  • Logical NOT (!) It is used to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. (From topic Relational and Logical Operators)
Truth Table
Relational and Logical Operators Truth table Javaform
Ex:
//Program related to Relational and Logical Operators..
class LogicOperators
{
public static void main(String args[])
{
int a=10,b=20,c=30;
System.out.println("(a>b)&&(a>c) is: "+((a>b)&&(a>c)));
System.out.println("(b>a)&&(b<c) is: "+((b>a)&&(b>c)));
System.out.println("!(a==b) is: "+!(a==b));
System.out.println("!(b!==c) is: "+!(b!==c));
System.out.println("(a==b)||(b==c) is: "+((a==b)||(b==c)));
System.out.println("(a!==b)||(b==c) is: "+((a!=b)||(b==c)));
}
}
Output
(a>b)&&(a>c) is: false
(b>a)&&(b<c) is: true
!(a==b) is: true
!(b!==c) is: false
(a==b)||(b==c) is: false
(a!==b)||(b==c) is: true

Logical Operator Output.-javaform
                              To get code file use me.

Continue to next topic Assignment and Unary Operators.

Begin your career in Digital Marketing,What is digital marketing? Digital Marketing online course. It's an current evolving technology which can give support to establish your own startup through Digital Marketing.

Do check my new startup Surprise Planners in HyderabadLavish Surprises our services are surprise party planners in Hyderabad, surprise giftssurprise birthday party planners Hyderabad, Wedding anniversary surprises, surprise planners Hyderabad.

Hi Friends, Please comment down your views in the comment section below. Thank you...

No comments:

Connect with Us by Subscribing here for more Updates..!

* indicates required