wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math.random" Watch "Math.random" New topic
Author

Math.random

yashendrakar chandrakar
Greenhorn

Joined: Oct 15, 2001
Posts: 15
following is the question taken from CompleteJava2Certification(by Robert-Heler)
_________________________________________________________________Question:
What is the value of the following expression?

Math.round(Math.random() + 2.50001);
Options:
A)2
B)3
C)can't say.
_________________________________________________________________
According to book
----------------
Correct selection is: B
Math.random() returns a double greater than or equal to 0.0 and less than 1.0. Math.random() + 2.50001 is a double greater than 2.5 and less than 3.5. Math.round() of any number between but not including 2.5 and 3.5 is 3.

But if i m not wrong
-------------------
suppose Math.random() return .99999 then
Math.round(Math.random() + 2.50001);
will be evaluated to
Math.round(.99999 + 2.50001);
or
Math.round(3.5);//it will return 4

so correct selection should be: C)

Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
I AM WITH U....
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!


Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
Cristian Negresco
Ranch Hand

Joined: Sep 15, 2001
Posts: 182
Hi,
you are right, consult the errata of the bock.
..Cristian
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math.random
 
Similar Threads
Q: Math.round(Math.random() + 2.50001; ????
RHE final exam question
RHE question re Math.round() and random()
Math.random() & .round() question from RHE
RHE Final #27