• 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

doubt in Conditional operator

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class EBH023 {
static String m1(boolean b){return b?"T":"F";}
public static void main(String [] args) {
boolean b1 = false?false:true?false:true?false:true;
boolean b2 = false?false true?false true?false:true));
boolean b3 = ((false?false:true)?false:true)?false:true;
System.out.println(m1(b1) + m1(b2) + m1(b3));
}}

Can somebody explain me how the assignment happens for b1,b2 and b3. I know it is using the conditional operator, but i am not able to get the flow.. The answer is False,False,True
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first

can be rewritten as


The assignment for b2 is similar.

The assignment for b3 can be rewritten using some intermediate boolean variables representing the the nested conditionals.


[ June 22, 2007: Message edited by: Garrett Rowe ]
[ June 22, 2007: Message edited by: Garrett Rowe ]
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b2 without smilies

which can be rewritten as

[ June 22, 2007: Message edited by: Manfred Klug ]
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic