This is a Java Program to Illustrate the Use of Various Boolean Operators.
Enter any two boolean values as input. After that we perform various boolean bitwise opeartions like AND, OR, XOR and NOT to get desired output.
Here is the source code of the Java Program to Illustrate the Use of Various Boolean Operators. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
import java.util.Scanner;
public class Boolean_Operators
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.print("Enter a:");
boolean a = s.nextBoolean();
System.out.print("Enter b:");
boolean b = s.nextBoolean();
boolean c = a | b;
boolean d = a & b;
boolean e = a ^ b;
boolean f = (!a & b) | (a & !b);
boolean g = !a;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("a|b = " + c);
System.out.println("a&b = " + d);
System.out.println("a^b = " + e);
System.out.println("!a&b|a&!b = " + f);
System.out.println("!a = " + g);
}
}
Output:
$ javac Boolean_Operators.java $ java Boolean_Operators Enter a:true Enter b:false a = true b = false a|b = true a&b = false a^b = true !a&b|a&!b = true !a = false
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Next Steps:
- Get Free Certificate of Merit in Java Programming
- Participate in Java Programming Certification Contest
- Become a Top Ranker in Java Programming
- Take Java Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Apply for Information Technology Internship
- Buy Java Books
- Practice Information Technology MCQs
- Apply for Java Internship
- Practice Programming MCQs