Detailed Print – Computer Sir Ki Class

Code Learning#JAVA#3698

## Conditional or Logical Operators AND, OR

Understanding the use of condition operators and (&&) and or (||)

## Learning Objectives

• Learning to use conditional or logical operators AND (&&) and OR(||).

## Source Code

```		class ConditionalOP
{
public static void main(String[] args)
{
int a=10,b=10;
boolean c;
c=(a==10) && (b>=10);
System.out.println(c);
c=(a>10) || (b>=10);
System.out.println(c);
c=(a>10) || (b>10);
System.out.println(c);
}
} ```

## Run Output

``````true
true
false

``````

## Code Understanding

int a=10,b=10; //Integer variables a and b are initialised with 10
boolean c; //A variable c is declared which stores the result of condition calculation

c=(a==10) && (b>=10); System.out.println(c);
Here first condition a==10 is true and second condition b>=10 is also true so due to && logical condition between them c will store true and accordingly printed..

c=(a>10) || (b>=10); System.out.println(c);
Here a>10 is false and b>=10 is true so due or || logical condition between the two c will get true  and accordingly printed.

c=(a>10) || (b>10); System.out.println(c);
Here a>10 is false and b>10 is also false so due or || logical condition between the two c will get false  and accordingly printed.

## Notes

• For && condition if the first condition is false then second condition is not evaluated. Similarly for || operator if first condition is true then second is not evaluated. This is called the short circuiting behaviour of conditional operators.

Suggested Filename(s): ConditionalOP.java