This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes operators (source K & B) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "operators (source K & B)" Watch "operators (source K & B)" New topic
Author

operators (source K & B)

krithika naya
Greenhorn

Joined: Oct 25, 2007
Posts: 10
1. class Maybe {
2. public static void main(String[] args) {
3. boolean b1 = true;
4. boolean b2 = false;
5. System.out.print(!false ^ false);
6. System.out.print(" " + (!b1 & (b2 = true)));
7. System.out.println(" " + (b2 ^ b1));
8. }
9. }

the output for line 7 is given as false.

XOR returns true if exactly one operand is true.here,b2=false and b1= true.
then how is it possible to get false for line 7.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by karthiga kengan:
...here,b2=false and b1= true.
then how is it possible to get false for line 7.

Check line 6. Is it testing whether b2 is true, or is it assigning true to b2?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
krithika naya
Greenhorn

Joined: Oct 25, 2007
Posts: 10
In line 6 b2 is assigned as true.Now i got it.

Thanks marc.
krithika naya
Greenhorn

Joined: Oct 25, 2007
Posts: 10
marc weber wrote:
Originally posted
...here,b2=false and b1= true.
then how is it possible to get false for line 7.

Check line 6. Is it testing whether b2 is true, or is it assigning true to b2?
 
 
subject: operators (source K & B)
 
Similar Threads
Question from Dan's exam.
Assignment Operator and wrappers
K & B boolean Question
booleanValue();
question about assertion