IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
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
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

Java Programming - Operators and Assignments - Discussion

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

Read more:

"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

Answer: Option C

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).

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!