• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

doubt in Conditional operator

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
b2 without smilies

which can be rewritten as

[ June 22, 2007: Message edited by: Manfred Klug ]
 
Create symphonies in seed and soil. For this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic