Tuesday, May 8, 2012

Code weirdness

I recently came across very strange behaviour in the tertiary operator:

<boolean-expression> ? <statement> : <statement>;

See if you can spot it. The idea is as follows. If the number is a round number (i.e. 4.0 or 8.0) then the number should be displayed without the trailing .0. However, if it is not, the fractional part should display. Here's the test class containing three tests... Which test(s) fails and why?

No comments:

Post a Comment