| 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
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
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
|
 |
 |
|
|
subject: Doubt in Math class
|
|
|