next up previous
Next: Check the random number Up: Part Two Previous: Part Two

Random doubles

1.
Create a new project of the Application variety, named Stats.
2.
In main, create an array of ten doubles.

3.
Write a method named randomizeArray that takes an array and the length of the array (number of elements), and that sets each element of the array to a random value. You can generate random values between 0.0 and 1.0 with the Math.random() method. It takes no arguments and returns a double.

4.
In main, invoke randomizeArray and then print a couple of the values.

5.
Write a method named printArray that takes an array and the length of the array (number of elements), and that prints each element of the array.

6.
Make main invoke printArray.

HINT: Notice how similar the descriptions of randomizeArray and printArray are? Maybe the code, which is just another kind of description, will be similar, too.



Allen B. Downey
3/18/1998