Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Bear Bibeault
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Jj Roberts
• Carey Brown
Bartenders:
• salvin francis
• Frits Walraven
• Piet Souris

# Math.random

Greenhorn
Posts: 15
• Number of slices to send:
Optional 'thank-you' note:
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)

Ranch Hand
Posts: 765
• Number of slices to send:
Optional 'thank-you' note:
I AM WITH U....
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!

Ranch Hand
Posts: 182
• Number of slices to send:
Optional 'thank-you' note:
Hi,
you are right, consult the errata of the bock.
..Cristian

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?