Home » JAVA Programming » Object & Classes » Question
  1. What is the value of “n” after this line of code has been executed?
    double n = Math.round ( 4.5 + Math.random() );
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
Correct Option: E

The Math.random() method returns a number greater than or equal to 0 and less than 1. so 4.5 will be greater than or equal to 4.5 and less than 5.5, we can be sure that Math.round() will round that number to 5.



Your comments will be displayed only after manual approval.