File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math problem" Watch "Math problem" New topic

Math problem

HiBob Chu
Ranch Hand

Joined: Aug 12, 2002
Posts: 86
What is the value of the following expression?
Math.round(Math.random() + 2.50001);
b.It is impossible to say.
which one is right?
Charu Murali
Ranch Hand

Joined: Jul 12, 2002
Posts: 37
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.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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.

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
HiBob Chu
Ranch Hand

Joined: Aug 12, 2002
Posts: 86
Yes, the answer is a but I don't think so.
I agree with you two's point. Thanks a lot!
I agree. Here's the link:
subject: Math problem
It's not a secret anymore!