• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Math problem

 
HiBob Chu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the value of the following expression?
Math.round(Math.random() + 2.50001);
a.3
b.It is impossible to say.
which one is right?
 
Charu Murali
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sine Math.random() function can return values from 0.0(inclusive) to 1.0(exclusive) we can not determine the input value for Math.round() function. So the ans is it is impossible to say.

Correct me if I am wrong.
Charu.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer will almost always be 3 ... but not always.
If Math.random() returns a double that is >= 0.99999, the answer will be 4.
 
HiBob Chu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the answer is a but I don't think so.
I agree with you two's point. Thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic