Java Logical Operators:

Java provides three logical operators such as :

  • && Logical-AND
  • || Logical-OR
  • ! Logical not

The logical operators && and || are used when we want to form compound conditions by combining two or more relations. For example:

X<y && x+y>y

Here this expression contains two expressions combined by && operator.

  • So according to the concept, if both expressions are true, then the output will be true, otherwise it will be false.
  • In case of logical or (||) operator, if any one expression is true, then the result is true, otherwise it is false.

Let's see a program :

class LogicalDemo
{
    public static void main(String args[])
    {
        int x=10,y=15;
        boolean p;
        boolean q;
        p=(x<y)&&((x+y)>x);
        q=(x>=y)||((x+y)<x);
        System.out.println(p);
        System.out.println(q);
    }
}

Output:

true
false

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment