Next: Part Four: The Long
Up: Assignment 8: The Exam
Previous: Reading
Write a method called inInterval that takes as arguments an
array of doubles, an integer that is the length of the array, and
two doubles, a and b.
The method should return an integer that indicates how many elements
of the array are between a and b, including elements that
are equal to a or b. You may assume that b > a.
- 1.
- Write the inInterval method as described above.
- 2.
- Write a main method that creates an array of doubles and
fills it with random numbers. You can use the randomizeArray
method from the previous assignment.
- 3.
- Test inInterval by measuring the fraction of random
numbers that fall in a given interval. For example, 100% of the
numbers should be in the range from 0.0 to 1.0. Half the numbers
should be in the range from 0.25 to 0.75.
Allen B. Downey
4/2/1998