• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Doubt in Math class  RSS feed

 
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
 
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
 
Java Cowboy
Sheriff
Posts: 16084
88
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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!