• 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

clarification if condition

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
this is my code


Can anyone let me know how to interpret second if condition.also what will be result here in second if.
Thanks.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you get that time of execution?
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Boolean b1=true;
Boolean b2=false;
Boolean b3=true;

if((b1=false)|(b1&b3)|(b1|b2))
System.out.println("beta");


Here first of all this will be executed.
(b1=false)
This is because expressions are evaluated from left to right
so b1 will become false. Since this will result in a boolean value so there will be no compile time error.
So the first value will be false

Then (b1&b3) will be evaluated. Since b1 is false so it will result in false.

Then (b1|b2) will be evalued. Since both b1 and b2 are false, so this will result in false.

So at last the whole condition will becode

false|false|false

which will result in false so beta will not be displayed.

Also your code has declarations Boolean and not boolean. Although this will work but I just want to remind you...
[ August 08, 2008: Message edited by: Ankit Garg ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic