info@meritcampus.com    +91-85006-22255
...
`

Print output using Boolean logical operators and Relational operators
What will be the output of the following program?
`public class BooleanVariables {    public static void main(String args[])     {        boolean A = true;        boolean B = false;        System.out.print((A | B) + " ");        System.out.print((A & B) + " ");        System.out.print((!A) + " ");        System.out.print((A ^ B) + " ");        System.out.print(((A | B) & A) + " ");    }}`

 A. true false false true true B. true false false false false C. false false false true true D. false false true true true E. Compilation Error or Runtime Error
Topic:

### User comments below.All of them might not be correct.

ans is A: here or and and operation are applied...1) if and only if both iput are false out put wil be false...other wise true...2)if both i/p true ouput o/p wil be true other wise false....like all the operations

Posted by Ashok Reddi    2014-02-26 13:34:13

Answer is A. The operators &, ^, and | are "bitwise" operators when the operands are "primitive integral" types. They are "logical" operators when the operands are Boolean. For &, the result is true if both operand values are true; otherwise, the result is false. For ^, the result is true if the operand values are different; otherwise, the result is false. For |, the result is false if both operand values are false; otherwise, the result is true. Logical NOT operator (!) reverses the logical state of its operand. Hence, the result.

Posted by Shaileshwar Sharma    2014-02-26 13:35:49

answer is A,because in first print true | false -> true , in second print true & false ->false ,in third print negation of true is false ,in fourth print XOR of A,Bis true,and finally (A | B)&A->will be true.

Posted by Naga Sinst    2014-02-26 13:38:25

Congratulations Ashok Reddi. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-02-27 04:18:36