Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What is the value of “d” in the following Java code snippet?
double d = Math.round ( 2.5 + Math.random() );

What is the value of “d” in the following Java code snippet?
double d = Math.round ( 2.5 + Math.random() );
a) 2
b) 3
c) 4
d) 2.5

Answer: b
Explanation: The Math.random() method returns a number greater than or equal to 0 and less than 1. so 2.5 will be greater than or equal to 2.5 and less than 3.5, we can be sure that Math.round() will round that number to 3.

Join The Discussion