Skip to main content

( ( h >= 0 && h < 24 ) ? h : 0)

2 replies [Last post]
robucsd
Offline
Joined: 2007-10-14
Points: 0

I am new to Java, could anyone please help explain this epression to me? Particularly the " ? h : 0)" portion of it.

Thanks, RobUCSD

( ( h >= 0 && h < 24 ) ? h : 0)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
forax
Offline
Joined: 2004-10-07
Points: 0

it's a if/then expression.

( h >= 0 && h < 24 ) is the condition,
the result of the expression is the value of h if the condition is true,
the result of the expression is 0 otherwise.

See the JLS:

Rémi

robucsd
Offline
Joined: 2007-10-14
Points: 0

Thanks for your help. I get it now.

Rob