import java.util.Random; // needed for Random class public class SortNumbers { public static void main(String[] args) { Random rg = new Random(); int[] nums = new int[20]; int[] num2 = new int[20]; for(int i = 0; i < 20; i++) { nums[i] = rg.nextInt(500); } System.out.println("Before the Insertion Sort"); System.out.println("==============="); for(int i = 0; i < 20; i++) { System.out.println(nums[i]); } // Implement the Insertion Sort int i; int j; int index; for (**1; i < nums.length; i++) { index = nums[i]; j = i; while ((j > 0) && (nums[j-1] > index)) { nums[j] = nums[j-1]; j = j - 1; } nums[j] = index; } System.out.println("After the Insertion Sort"); System.out.println("=============="); // Print out the array for(int k = 0; i < 20; i++) { System.out.println(nums[i]); } // Create for loop to fill the 2nd array with 20 numbers from 0-499, use the one up top as a guide for(int k = 0; k < 20; k++) { num2[k] = rg.nextInt(500); } System.out.println("Before the Selection Sort"); System.out.println("==============="); for(int k = 0; k < 20; k++) { System.out.println(nums[k]); } // Implement the Selction Sort code int a, b; int min, temp; for (a = 0; a < nums.length-a; a++) { min = a; for (b = a+1; b < nums.length; b++) { if (nums[b] < nums[min]) min = b; } //swap temp = nums[a]; nums[a] = nums[min]; nums[min] = temp; } System.out.println("After the Selection Sort"); System.out.println("=============="); // Print out the array for(int k = 0; k < 20; k++) { System.out.println(num2[k]); } } }