user1905170
user1905170

Reputation: 67

Sorting array of random numbers

Hey guys looking for some help with my ArrayTester class... The array is supposed to 1.create a 20 element int array and populates it with random elements in the range 20 through 65 (both inclusive). -I Believe I have already done this.

2.Use the java.util.Random class with a seed of 2621 to generate repeatable output for the data. -I have also already done this

3.The tester class should then test each of these methods(mean, median, mode, max, min, standard divination) -this is where I'm having trouble, I already have the code for the mean, mode, max, min, and standard divination.. the problem I'm having is with the median as i would like to sort my array in the tester class before having it called by my main Class.

Is there any way to do this?

Here is my code:

public class ArrayTest
{
    public static void main(String [] args)
    {
        int[] numbers;
        numbers = new int [20];
        Random rand = new Random(2621); 
        int maxRange = 65;
        int minRange = 20;

        for(int i=0; i<20; i++)
        {
            numbers[i] = rand.nextInt(maxRange - minRange + 1) + minRange;
            //checks to see if printing out ocrrectly
            System.out.println(numbers[i]);

        }
    }
}

Upvotes: 1

Views: 4804

Answers (1)

iTech
iTech

Reputation: 18430

You can use Arrays.sort(numbers);

Upvotes: 5

Related Questions