• Post Reply Bookmark Topic Watch Topic
  • New Topic

precedence  RSS feed

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


But b2 value is false printing and for the evaluation (b2 != b1) also takes
(false != false) for execution.But i am always going like (true !=false) since !b2 changed the b2 value as true.


i have checked the JLS 15.7.1 specification.



prints:
9

It is not permitted for it to print 6 instead of 9.But like this,it is not happening on the 1 problem.
[ March 12, 2007: Message edited by: Shiva Mohan ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"!b2" does not change the value of b2.

What happens is you evaluate b2, which is false, and remember it in a temporary spot. then, the '!' operator changes that temp value to true - not b2.

so, "b2 != b1" evaluates to false.
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred,still confusing

int i=1;
i1=i++ + +i; //------ 1+2
System.out.println(i1);

i1 is printing 3 . !b2 is not changing b2 value true.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

int i=1;
i1=i++ + +i; //------ 1+2
System.out.println(i1);

What does the post increment operator have to do with the boolean negation operator? I don't understand how you think these should be related.

the boolean negation operator does NOT change the value of the boolean. that's the story, plain and simple.

saying (!b1) says "evaluate b1, then take the opposite boolean value, then use that in place of the '!b1'".

nowhere does it alter the value of b1.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!