This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Math.random()

 
Bill Boyle
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While taking a practice test I ran across this question:
What is the value of the following expression:
Math.round(Math.random() + 2.50001);
A. 2
B. 3
C. It is impossible to say
I thought the answer should be C, but the book said B. Most the time the result should be 3. But is it possible for random() to return .999999
It that case the value would be 4.
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might need to look into this thread.
 
Muzammil Khan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill Boyle,
I agree with you the answer should be definetly C. It is impossible to say .
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic