• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about -0.0 and +0.0

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A better question would be to test the result of System.out.println(Math.min(-0.0,0.0))
reply
    Bookmark Topic Watch Topic
  • New Topic