Question: Exercise 21: Math.random( ) is a method in the Java library that computes a random double value between 0 and 1. For example, the statement

Exercise 21: Math.random( ) is a method in the Java library that computes a random double value between 0 and 1. For example, the statement double x = Math.random(); assigns to the variable x a random double between 0 and 1. Write a program that tests how well Math.random() works. More precisely, write a program that calls Math.random() 1,000 times to create 1,000 values, keeping track of how many of them are greater than 0.5, and then prints out the result. Your program should theoretically print out a number very close to 500.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!