Why the output of following code is 9.0 and not 9 ? If ternary operator is nothing but short form of if-else branch then why java compiler is promoting int to double ?
Java needs to know the type of the result at compile time. So as this ternary operator can result an int or a double, the compiler chooses the double as the result type.