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.

What is the Sieve of Eratosthenes?

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:

  1. Write down the numbers 1, 2, 3, ..., n. We will eliminate composites by marking them. Initially all numbers are unmarked.
  2. Mark the number 1 as special (it is neither prime nor composite).
  3. Set k=1. Until k exceeds or equals the square root of n do this:

Use an array of booleans to implement the Sieve and find all prime numbers between 2 and a given value.