Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Math class

 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes ofcourse
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic