• 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

assignment operators

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code:
class T
{
public static void main(String arg[])
{
boolean b1=false,b2=false,b3=true;
b1&=true;//line1
b2|=b1; //line2
b3^=b2|=b3;//line3
boolean b4=false | false;//line4
System.out.println(b1+"\n"+b2+"\n"+b3+"\n"+b4);
}
}
output:false
:true
:false
:false
My Question:why line2 is true.If line2 is true
than line4 also true.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Line 2 doesn't produce a 'true'. It is line line 3 which is assigning 'true' to b2. Try commenting line 3... value b2 remains false.
or just add
System.out.println(b2);
before line 3.
Hope you got it !!
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can u tell me how this line b3^=b2|=b3;//line3
is getting executed with b2=true.
-Sanjana
 
H Gokulam
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

can u tell me how this line b3^=b2|=b3;//line3
is getting executed with b2=true.


Assignment operators are evaluated right to left.
b3^=b2|=b3 will be like b3 = b3 ^ (b2 = b2 | b3)
ie: b3 = b3 ^(b2 = false | true) here b2 will be assigned with value 'true'
 
jaysingh solanki
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks hari now my concept is clear
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic