A student told me that he had a major discovery:
Package org.leno.exe cise1;
Public class answer {
Public static void main (string [] ARGs ){
Int I = 5;
System. Out. println ("value is" + (I> 5 )? 9.0: 9 ));
}
}
Xu Why is the result 9.0 returned by the teacher? It's strange. Is this a Java bug?
Haha. At first glance, it is a little weird. Why is it true? Of course this is not the case. We were confused by some strange appearances. See the truth:
Public static void main (string [] ARGs ){
Int I = 5;
System. Out. println (I> 5? 1.0: 2 );
}
The result is 2.0. See it. In fact, the output is still the latter, but in the expression of the Three-object operator, there is a number (1.0) of the double type involved in the operation. Therefore, we recommend that you upgrade the type in Java. The result is converted to the double type. Therefore, the output result is 2. 0. So the above output 9.0 is quite understandable. Now you understand.