Exercises 3
1. Write methods to determine the following statistics for an array of ints. Create a separate method for each statistic. minimum, maximum, average, standard deviation, mode.
2. Write a method to reverse the contents of an array of ints.
3. Write a method to shuffle the contents of an array of ints. Use the Math.random method. You can pick a random int with the following code:
// assume list is an array of ints
int rand = (int)( Math.random() * list.length );
4. The Sieve of Eratosthenes is another method for calculating prime numbers.
From http://www.math.utah.edu/~alfeld/Eratosthenes.html at the University of Utah.
A prime number is a natural number greater than 1 that can be divided without remainder only by itself and by 1. Natural numbers n that can be divided by a number less than n and greater than 1 are composite numbers. The Sieve of Eratosthenes identifies all prime numbers up to a given number n as follows:
2m, 3m, 4m, ...as composite. (Thus in the first run we mark all even numbers greater than 2. In the second run we mark all multiples of 3 greater than 3.)
Use an array of booleans to implement the Sieve and find all prime numbers between 2 and a given value.