Write a program that inputs 10 integers into an array, sort thearray with a sele
ID: 3610115 • Letter: W
Question
Write a program that inputs 10 integers into an array, sort thearray with a selection sort, and displays its content before andafter the sort. ArrayJAVA PROGRAMMING JGRASP Perferably Ask for 10 integers then put in array. Then sort, and thendisplay.Ask about play again. Make sure it asks if you want to play again. Make try, catch for the JOptionPane to make sure that they areinputing integers. Use while, and for loops when necessary.
Use this method for the selection sort:
static void selectionSort(int[] a){ for(int i = 0; i<a.length- 1; i++){ int minIndex =findMinimum(a,i); if(minIndex !=i) swap(a,i, mindIndex); } } int findMinimum(int[]a, int first){ int mindIndex = first; for(int i = first + 1; i < a.length; i++) if(a[i] < a[minIndex]) minIndex = i; return minIndex; } static void swap(int[] a, int x, int y){ int temp = a[x]; a[x] = a[y]; a[y] = temp; }
Array
JAVA PROGRAMMING JGRASP Perferably Ask for 10 integers then put in array. Then sort, and thendisplay.Ask about play again. Make sure it asks if you want to play again. Make try, catch for the JOptionPane to make sure that they areinputing integers. Use while, and for loops when necessary.
Use this method for the selection sort:
static void selectionSort(int[] a){ for(int i = 0; i<a.length- 1; i++){ int minIndex =findMinimum(a,i); if(minIndex !=i) swap(a,i, mindIndex); } } int findMinimum(int[]a, int first){ int mindIndex = first; for(int i = first + 1; i < a.length; i++) if(a[i] < a[minIndex]) minIndex = i; return minIndex; } static void swap(int[] a, int x, int y){ int temp = a[x]; a[x] = a[y]; a[y] = temp; }
JAVA PROGRAMMING JGRASP Perferably Ask for 10 integers then put in array. Then sort, and thendisplay.Ask about play again. Make sure it asks if you want to play again. Make try, catch for the JOptionPane to make sure that they areinputing integers. Use while, and for loops when necessary.
Use this method for the selection sort:
static void selectionSort(int[] a){ for(int i = 0; i<a.length- 1; i++){ int minIndex =findMinimum(a,i); if(minIndex !=i) swap(a,i, mindIndex); } } int findMinimum(int[]a, int first){ int mindIndex = first; for(int i = first + 1; i < a.length; i++) if(a[i] < a[minIndex]) minIndex = i; return minIndex; } static void swap(int[] a, int x, int y){ int temp = a[x]; a[x] = a[y]; a[y] = temp; }
static void selectionSort(int[] a){ for(int i = 0; i<a.length- 1; i++){ int minIndex =findMinimum(a,i); if(minIndex !=i) swap(a,i, mindIndex); } } int findMinimum(int[]a, int first){ int mindIndex = first; for(int i = first + 1; i < a.length; i++) if(a[i] < a[minIndex]) minIndex = i; return minIndex; } static void swap(int[] a, int x, int y){ int temp = a[x]; a[x] = a[y]; a[y] = temp; }