1  import java.util.Scanner;
  2  
  3  /**
  4     This program measures how long it takes to sort an
  5     array of a user-specified size with the selection
  6     sort algorithm.
  7  */
  8  public class SelectionSortTimer
  9  {  
 10     public static void main(String[] args)
 11     {  
 12        Scanner in = new Scanner(System.in);
 13        System.out.print("Enter array size: ");
 14        int n = in.nextInt();
 15  
 16        // Construct random array
 17     
 18        int[] a = ArrayUtil.randomIntArray(n, 100);
 19        SelectionSorter sorter = new SelectionSorter(a);
 20        
 21        // Use stopwatch to time selection sort
 22        
 23        StopWatch timer = new StopWatch();
 24        
 25        timer.start();
 26        sorter.sort();
 27        timer.stop();
 28        
 29        System.out.println("Elapsed time: " 
 30              + timer.getElapsedTime() + " milliseconds");
 31     }
 32  }
 33  
 34