## Free Data Structures and Algorithms Course

### How to use Logical Operators in Java ?.

Logical Operators in Java -

Program to demonstrate working of Logical Operators in Java.

```public class LogicalOperators {

public static void main(String[] args) {

// Logical AND Operator & , &&
// F & F --> F
// T & F --> F
// F & T --> F
// T & T --> T

int number1 = 5;
int number2 = 10;

boolean b1, b2, b3, b4, b5, b6, b7;

b1 = (number1 > 6) && (number2 > number1);
System.out.println(b1);

b2 = (number1 > 4) && (number2 > number1);
System.out.println(b2);

// Logical OR Operator | , ||
// F | F --> F
// T | F --> T
// F | T --> T
// T | T --> T

b3 = (number1 > 6) || (number2 > 15);
System.out.println(b3);

b4 = (number1 > 3) || (number2 > 11);
System.out.println(b4);

// Logical NOT Operator !

// !T ---> F
// !F ---> T

b5 = !(number1 > 3);
System.out.println(b5);

b5 = !(number1 > 6);
System.out.println(b5);

// Logical XOR Operator ^
// F ^ F ---> F
// T ^ F ---> T
// F ^ T ---> T
// T ^ T ---> F

b6 = (number1 > 3) ^ (number2 > 6);
System.out.println(b6);

b6 = (number1 > 3) ^ (number2 > 11);
System.out.println(b6);

}

} ```

Output of the program :

© 2021 Learn Java by Examples Template by Hubberspot