File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math problem" Watch "Math problem" New topic
Author

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);
a.3
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.
Charu.
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!
 
Don't get me started about those stupid light bulbs.
 
subject: Math problem