aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Math class 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 "Doubt in Math class" Watch "Doubt in Math class" New topic
Author

Doubt in Math class

Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
source Maaji 28
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.

Answer B

Doubt: On running I get
-0.0
0.0
true
So is +0.0 same as 0.0?


regards,
Gitesh
Thiru Mu
Greenhorn

Joined: Aug 30, 2007
Posts: 23
yes ofcourse
Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
I modified the code as follows:



And the output I got was:
-0.0
0.0
true

This means that -0.0=0.0. But that is not true because
System.out.println(Math.min(-0.0,0.0)); gives -0.0

So how am i getting true for line 3??

PLEASE help,
Gitesh
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Originally posted by Gitesh Ramchandani:
This means that -0.0=0.0. But that is not true because
System.out.println(Math.min(-0.0,0.0)); gives -0.0

Why do you think that if System.out.println(Math.min(-0.0,0.0)); gives -0.0, the first statement (-0.0 == 0.0) is not true?

If System.out.println(Math.min(-0.0,0.0)); gives -0.0 it does not mean that -0.0 == 0.0 cannot be true.
[ September 04, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt in Math class