Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about -0.0 and +0.0

 
david hu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer of the question(from www.jtips.net mock ex2) is 2.But when I run the program, I got the following output:
Prints 0.0 , there's no +0.0
Is the answer wrong?
class Test {

Test() {
this(-0.0 == + 0.0);
}
Test(boolean b) {
if(b)
System.out.println(Math.max(-0.0, + 0.0));
else
System.out.println(Math.min(-0.0, + 0.0));
}
public static void main(String [] args) {
new Test();
}
}
1.Prints � 0.0
2.Prints + 0.0
3.Compile-time error occurs.
4.No output is printed.
 
Namrata Shetty
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u r right. 0.0 gets printed and not +0.0.
i think the question is trying to test if u know Math.max(-0.0,+0.0) function differentates between -0.0 & +0.0
 
Alex Sbityakov
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A better question would be to test the result of System.out.println(Math.min(-0.0,0.0))
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic