CSCI-1320 Lab: Sorting I

Instructor: Todd Dole

Purpose Statement

This program gives practice using a sorting algorithm.

Instructions

In this program, you will create an array of 100 random doubles between 0 and 1000. You can iterate through your array and generate a random number for each element using the following code:


                double[] randomNumbers = new double[100];
                for (int i = 0; i < 100; i++) {
                    randomNumbers[i] = Math.random() * 1000;
                }
            

Once you have generated the random numbers, sort them from smallest to largest using your own implementation of selection sort or insertion sort.

Finally, iterate through the list again and print out the results. Print one number per line, and print only two digits after the decimal.

Sample output: (The numbers will vary each time you run the program)

                0.97
                1.38
                17.24
                51.41
                ...