Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing

# Java Programming - Operators and Assignments - Discussion

@ : Home > Java Programming > Operators and Assignments > Finding the output - Discussion

"Actions speak louder than words."
- (Proverb)
10.

What will be the output of the program?

``````class SSBool
{
public static void main(String [] args)
{
boolean b1 = true;
boolean b2 = false;
boolean b3 = true;
if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */
System.out.print("ok ");
if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/
System.out.println("dokey");
}
}
``````

 [A]. ok [B]. dokey [C]. ok dokey [D]. No output is produced [E]. Compilation error

Explanation:

The & operator has a higher precedence than the | operator so that on line 8 b1 and b2 are evaluated together as are b2 & b3. The final b1 in line 10 is what causes that if test to be true. Hence it prints "dokey".

 Bhagyashree said: (Mon, Jan 10, 2011 12:48:18 AM) Please any one can explain it I have confusion.

 Sinu Jos said: (Tue, Aug 23, 2011 11:24:05 AM) Can anybody explain me?

 Vinay said: (Sat, Dec 17, 2011 07:11:29 PM) First if is false and second one is true. Hint: Truth table concept is working here apply that logic you will get ans why first if is false and second one is true.

 Govind said: (Tue, Jun 26, 2012 04:11:56 PM) I can't understand please explain in the deeply.

 Mayur Raiyani said: (Tue, Jul 3, 2012 01:02:01 PM) Here is explanation: First condition: (b1 & b2 | b2 & b3 | b2). (true & false | false & true | false). (false | false | false). (false). Second Condition: (b1 & b2 | b2 & b3 | b2 | b1). (true & false | false & true | false | true). (false | false | false | true). (false | true). (true).