• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

clarification if condition

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
what you get that time of execution?
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • 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 ]
 
Oh. Hi guys! Look at this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic