• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

operators (source K & B)

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic