About Question com.enthuware.jfcja.v8.2.419 :

Oracle Certified Foundations Associate Java Certification Questions and Discussion
1Z0-811

Moderator: admin

Post Reply
vugar.asadov
Posts: 1
Joined: Thu Dec 07, 2017 6:41 am
Contact:

About Question com.enthuware.jfcja.v8.2.419 :

Post by vugar.asadov »

1 + Math.round(Math.random()*9) will return a random number between 1 and 10.

Math.random()*9 will return a double between 0.0 to less than 9.0. Rounding it will give you a range of 0.0 to 10.0 (both inclusive). Adding 1 to it will give you a range of 1.0 to 11.0 (both inclusive).

the option says that expression will return random number between 1 and 10, but explanation says that it will give a you a range of 1.0 to 11.0 (both inclusive). so why this option is correct statement?

admin
Site Admin
Posts: 9504
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.jfcja.v8.2.419 :

Post by admin »

The option is correct but the explanation is incorrect. It should say:
Rounding it will give you a range of 0.0 to 9.0 (both inclusive). Adding 1 to it will give you a range of 1.0 to 10.0 (both inclusive).
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest