Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

question about this code

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
why this code has a "?"
radius= (circleRadius>=0.0? circleRadius:0.0);


Thanks

Larry
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that blank post. Tyring to figure out how to make a post.
Any way, I believe that the '?' your asking about is like putting an 'if' statement in the middle of an expression. The example I see in 'Just Java2' 5th edition gives an example on page 131.
So
radius = ( circleRadius >= 0.0 ? circleRadius : 0.0 );
would mean that circleRadius would be evaluated if it 's >= 0.0 (true) and 0.0 if it's not >= 0.0(false).
My first post. Hope I didn't confuse 'ya.
Thanks,
Ken
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ken, you can delete the dead post via the edit icon.
The expression "boolean expression" ? "true alternative" : "false alternative" has been inherited from C/C++.
If "boolean expression" is true then the result of the expression is the result of the "true alternative" expression, else it is the result of the "false alternative" expression. The type of the result expression is the "widest" of the types of the two alternatives.
So true ? 9 : -1.0 will result in 9.0 (a double) being returned, and false ? 9 : -1.0 will result in -1.0 (also a double) being returned.
Its a bit tricky so look this up in your Java books because it can appear in Java Certification exams.
-Barry
 
Larry Lai
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Barry,
Thanks a lot
I understand it now.
Larry
 
Ken Cobbs
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Barry,
I'll get this posting down(sometime).
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic