This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Rounding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Rounding" Watch "Rounding" New topic
Author

Rounding

Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
OK, I thought this would be an easy question, but I got it wrong:
What is the value of the following expression:
Math.round(Math.random() + 2.50001);
Answer: 3
Isn't it possible the value of Math.random() could be 0.99999 ?
If it was then the value of the expression would be 3.5 which would be rounded to 4, no?
Thanks,
Drew
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4786
    
    8

Drew, if this is coming from the RHE mock exam, the answer given is wrong. You are right about round() and random(), so the correct answer to that question would be "impossible to say"

Junilu - [How to Ask Questions] [How to Answer Questions]
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
THANK YOU!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rounding