aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math.random() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math.random()" Watch "Math.random()" New topic
Author

Math.random()

Bill Boyle
Greenhorn

Joined: Aug 10, 2003
Posts: 12
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.


Thank you,<br />Bill Boyle
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
You might need to look into this thread.


Mani
Quaerendo Invenietis
Muzammil Khan
Greenhorn

Joined: Jul 22, 2003
Posts: 8
Hi Bill Boyle,
I agree with you the answer should be definetly C. It is impossible to say .


Muzz<br />MSC Computing<br />Nothing worth while will ever be achieved without DEEP THOUGHT AND HARDWORK - J.R.D TATA
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Math.random()
 
Similar Threads
Error in "final" test on cd for RHE book
Math.random() & .round() question from RHE
Math.random
RHE Final #27
RHE question re Math.round() and random()