Ask Question

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

+3
Answers (1)
  1. 18 May, 00:06
    0
    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers