Write a program that inputs 10 integers into an array, sort thearray with a sele
ID: 3610116 • 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; }
Explanation / Answer
please rate - thanks I think this is everything import javax.swing.*; public class selectionsort {public static void main(String[] args) {int []num=new int[10]; int n=10,i; String input,str="",yorn="Y"; while(yorn.charAt(0)=='Y'||yorn.charAt(0)=='y') {str=""; for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.