> int a = 5;
>
[quoted text clipped - 7 lines]
>
> but output is 9.0
An expression using the conditional operator ?: can only have one type
that must be determined at compile time. Since one of the operands is
float, the other is promoted to float and it becomes a float
expression.
It's described here, and the rule that's applied is called binary
numeric promotion:
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#290293
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Patricia Shanahan - 15 Sep 2006 18:21 GMT
>> int a = 5;
>>
[quoted text clipped - 19 lines]
>
> /gordon
If this is specifically for printing, could you use strings rather than
numbers?
System.out.println("Value is - " + ((a < 5) ? "9.9" : "9"));
Patricia