Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

operators (source K & B)

 
krithika naya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
krithika naya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In line 6 b2 is assigned as true.Now i got it.

Thanks marc.
 
krithika naya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic