title: How to copy random generated numbers to the selection sort method. (JAVA)
body: <pre><code>import java.util.ArrayList;
  import java.util.Random;
  
  
  public class Sorting
  {
     public static int numOfComps = 0,
                       numOfSwaps = 0;
  
     public static void main(String[] args)
     {
          System.out.println("\nOriginal order:");
          int size = 5;
  
          ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;(size);
  
  
          for(int i = 1; i &lt;= size; i++)
          {
             list.add(i);
          }
  
          Random rand = new Random();
          while(list.size() &gt; 0)
          {
           int index = rand.nextInt(list.size());
           System.out.print(list.remove(index) + " ");
          }
  
        System.out.println();
  
         int[] test = convertIntegers(list);
         int[] a = new int[5];
  
         // Selection Sort
         System.out.println("\n\nSelection Sort");
  
         // Display copy of random generated number original order
         System.out.println("\nOriginal order:");      
         System.arraycopy(test, 0, a, 0, test.length);
         System.out.println(a + " ");
  
         // Selection Sort method
         selectionSort(a);
  
         System.out.println("\nSorted order: ");
         for(int element : a)
           System.out.print(element + " ");
      }
  
      public static int[] convertIntegers(ArrayList&lt;Integer&gt; integers)
      {
          int[] num = new int[integers.size()];
          for (int i=0; i &lt; num.length; i++)
          {
          num[i] = integers.get(i).intValue();
          }
          return num;
       }
  
     public static void selectionSort(int[] array)
     {
        int startScan;   // Starting position of the scan
        int index;       // To hold a subscript value
        int minIndex;    // Element with smallest value in the scan
        int minValue;    // The smallest value found in the scan
  
        // The outer loop iterates once for each element in the
        // array. The startScan variable marks the position where
        // the scan should begin.
        for (startScan = 0; startScan &lt; (array.length-1); startScan++)
        {
           // Assume the first element in the scannable area
           // is the smallest value.
           minIndex = startScan;
           minValue = array[startScan];
  
           // Scan the array, starting at the 2nd element in
           // the scannable area. We are looking for the smallest
           // value in the scannable area. 
           for(index = startScan + 1; index &lt; array.length; index++)
           {
              if (array[index] &lt; minValue)
              {
                 minValue = array[index];
                 minIndex = index;
              }
  
              // Counts the number of values comparisons
              numOfComps ++;
           }
           // Counts the number of values swaps
           if(minIndex != startScan)
              {
                  numOfSwaps ++;
              }
  
           // Swap the element with the smallest value 
           // with the first element in the scannable area.
           array[minIndex] = array[startScan];
           array[startScan] = minValue;
  
        }
         System.out.println("\nNumber of comps = " + numOfComps);
         System.out.println("Number of swaps = " + numOfSwaps);
      }
  }
  </code></pre>
  
  <p>How do I write code to copy random generated numbers to the selection sort method so that the random generated numbers can be displayed as an exact copy under the displayed heading "Selection Sort" as well as displaying the number of comparisons and swaps, and the sorted order? The code I have provided is not working properly. Thank you for any help.</p>