Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Math problem
HiBob Chu
Ranch Hand
Posts: 86
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 37
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 1056
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 86
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes, the answer is a but I don't think so.
I agree with you two's point. Thanks a lot!
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Math.random() !!!!!!
RHE Final #27
RHE question re Math.round() and random()
Math.random
RHE final exam question
More...