Operators on Boolean Values in Java Programming
Previous | Home | Next |
The boolean operators include relational operators and logical operators. Only boolean expressions can be used in control flow statements and as the first operand of the conditional operator.
The boolean operators include relational operators and logical operators. Only boolean expressions can be used in control flow statements and as the first operand of the conditional operator ?:. An integral value x can be converted to a value of type boolean, following the C language convention that any nonzero value is true, by the expression x!=0.
An object reference obj can be converted to a value of type boolean, following the C language convention that any reference other than null is true, by the expression obj!=null.
class Bool{
public static void main(String args[]){
// these are boolean variables
boolean A = true;
boolean B = false;
System.out.println("A|B = "+(A|B));
System.out.println("A&B = "+(A&B));
System.out.println("!A = "+(!A));
System.out.println("A^B = "+(A^B));
System.out.println("(A|B)&A = "+((A|B)&A));
Previous | Home | Next |