This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.

Question: public class check{ public static void main(String args[]){ System.out.println(Math.min(-0.0,+0.0)); System.out.println(Math.max(-0.0,+0.0)); System.out.println(Math.max(0.0,+0.0)); System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0)); } } This prints: -0.0 0.0 0.0 true How does the last stmt return "true" if -0.0 and 0.0 are considered to be different values by Math.min and Math.max?

Sharda Vajjhala
Ranch Hand

Joined: Nov 14, 2001
Posts: 57

posted

0

I realized as soon as I posted this message that the last stmt is actually an expression and except for the Math.min and Math.max everything else considers -0.0 and +0.0 to be equal. Hence the output of "true" Sharda