• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assignment operators

 
jaysingh solanki
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
H Gokulam
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • 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 !!
 
sanjana narayanan
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks hari now my concept is clear
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic