This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ternary query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ternary query" Watch "ternary query" New topic

ternary query

Vishal Mungi

Joined: Mar 24, 2005
Posts: 24
class f
public static void main(String[] args)
int x=6;
double d=7.7;

why does this print 9.0 & not 9 ???
Vishal Mungi

Joined: Mar 24, 2005
Posts: 24
oh yes , i got it ..
its the same as a method returning one of two values & it
just converts both to the same datatype, in this case the 'bigger of the two'.
[ October 02, 2005: Message edited by: Vishal Mungi ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
That seems like the logical answer without looking at the JLS itself. It seems that the ternary operator promotes its operands just like other operators do. Since 99.9 is a double and 9 is an int, the later is promoted to a double.


Java API Documentation
The Java Tutorial
subject: ternary query
It's not a secret anymore!