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.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Check Java Books
- Check Programming Books
- Practice Information Technology MCQs
- Apply for Java Internship
- Practice BCA MCQs