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.
Related Posts
Which command is used to undelete a bunch of files with extension .doc that you have just deleted?
The …. operating system was initially created in the early 1970s at AT and T’s Bell Labs
The most recent version of MAC OS is based on the …. operating system
Which one of the following is not a multitasking operating system?
The number of character contained in primary name (DOS)?
The …. is the drive containing the files to be copied
A …. is a flash memory storage device that plugins into a USB port
Join The Discussion