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.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math.min and Math.max - exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math.min and Math.max - exam question" Watch "Math.min and Math.max - exam question" New topic
Author

Math.min and Math.max - exam question

Sharda Vajjhala
Ranch Hand

Joined: Nov 14, 2001
Posts: 57
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math.min and Math.max - exam question