Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock exam question" Watch "Mock exam question" New topic
Author

Mock exam question

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

What will happen if you invoke the following method?
1: public void check()
2: {
3: System.out.println(Math.min(-0.0,+0.0));
4: System.out.println(Math.max(-0.0,+0.0));
5: System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0));
6: }
A) prints -0.0, +0.0 and false.
B) prints -0.0, +0.0 and true.
C) prints 0.0, 0.0 and false.
D) prints 0.0, 0.0 and true.
why the right answer is B not A?
thanks
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi,
Direct from the JLS:

Positive zero and negative zero compare equal; thus the result of the expression 0.0==-0.0 is true and the result of 0.0>-0.0 is false. But other operations can distinguish positive and negative zero; for example, 1.0/0.0 has the value positive infinity, while the value of 1.0/-0.0 is negative infinity.

Regards,
Manfred.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
dianyjava,
Please change your name to be compliant with JavaRanch's naming policy.
Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
Thanks
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Dian He
Greenhorn

Joined: Aug 03, 2001
Posts: 12

Hi Manfred,
Thanks for your explanation, I understood now, thanks again.
Regards
Dian He

Hi Thomas,
Sorry about the name, I have changed it now, I wish I will be one good member of this professional forum.
Regards
Dian He
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Mock exam question