Chaspen9005 Chaspen9005
  • 14-07-2019
  • Computers and Technology
contestada

What is the value of "d" after this line of code has been executed? double d = Math.round ( 2.5 + Math.random() ); A. 2 B. 3 C. 4 D. 2.5

Respuesta :

PhantomWisdom PhantomWisdom
  • 16-07-2019

Answer:

  3

Explanation:

Math.random() is the function which gives the value greater than or equal to 0.0 and less than 1.0. it gives the double type value.

Math.round is also the function which gives the closest long to the argument.

for example:

Math.round(2.5) it gives 3.

so, Math.random() generate number 0.000 to 0.999

maximum possible value inside the Math.round(2.5+0.999) which is equal to

Math.round(3.499) which gives 3 not 4 when it 3.5 then it gives 4.

therefore, the result is 3

Answer Link

Otras preguntas

Which word or words and punctuation best corrects any errors in the sentence? I'd really like to go excuse me, I'm going to sneeze but I'm not feeling up to it
A system of equations is shown below: y = 3x − 7 y = 2x + 1 What is the solution to the system of equations? (8, 17) (−8, 17) (−8, −17) (8, −17) x
How does aerobic exercise help prevent cardiovascular diseases?
how are american literature and the american identity interrelated
What is the LCM of 3 and 7? 3 7 14 21
3/9 in simplest form
Which decimal number is equivalent to 9/1000? 0.009 0.18 0.9 0.0009
the term duration refers to
What is the solution to the inequality? 5x + 8 > –12 A. x < –4 B. x > –4 C. x < 4 D. x > 4
Gravel, crushed rock, cinder—these are used as ballast on railroad beds. correct incorrect