• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question from Mock

 
Ali Haider
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why B is the correct Answer.
Q # 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.
Question is from Majji Exam. Any comments are welcome.
 
S Dave
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the ans is: b
ie, -0.0
0.0
true
-0.0 is considered to be equal to 0.0 in comparisons.
 
Ishaan Mohan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The answer is b.
for Math.max() and Math.min -0.0 and +0.0 are different
for equality -0.0 is equal to +0.0
the output you get is -0.0, 0.0 ,true
 
Ali Haider
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx to both of u...... I got it now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic