aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unable to Understand Output Of Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Unable to Understand Output Of Code" Watch "Unable to Understand Output Of Code" New topic
Author

Unable to Understand Output Of Code

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

This is the code...

What will happen if you invoke the following method?


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.

Correct answer: B.

Explanation:The order of floating/double values is -Infinity --> Negative Numbers/Fractions --> -0.0 --> +0.0 --> Positive Numbers/Fractions --> Infinity.

Source: http://www.geocities.com/skmajji/Main.html


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18748
    
  40

It will help if you explain to us, what did you expect the output of the code to be?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Vinod Kumar Kommineni
Ranch Hand

Joined: Jun 12, 2008
Posts: 54

Hi ankit the answer is correct .. check this source to get clarified

http://www.janeg.ca/scjp/oper/comparison.html


Regards
vinod SCJP 6.0
Vinod Kumar Kommineni
Ranch Hand

Joined: Jun 12, 2008
Posts: 54

positive and negative zero are considered equal therefore
-0.0 < 0.0 is false and -0.0 <= 0.0 is true but this is not the case with Math.min() and Math.max()... the last statement is indeed -0.0==+0.0 therefore its true . i hope its your doubt.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

thanks......Now I got it completely........
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unable to Understand Output Of Code