Title: There is an array that has been sequenced. Now enter a number that requires it to be inserted into the array as it was originally.
Public Static voidMain (string[] args) {int[] arr =New int[9]; //Initialize the number of length-1Random random =NewRandom (); for(inti = 0; i < arr.length-1; i++) { inttemp = random.nextint (100); Arr[i]=temp; } //Sortsort (arr); //Print ResultsSystem.out.println ("Sort before inserting"); for(inti = 0; i < arr.length; i++) {System.out.print (Arr[i]+ "\ T"); } System.out.println (""); //Insert a numberScanner Scanner =NewScanner (system.in); arr[0] =Scanner.nextint (); //Print the results after insertingsort (arr); System.out.println ("Sort after insert"); for(inti = 0; i < arr.length; i++) {System.out.print (Arr[i]+ "\ T"); } System.out.println (""); } //Sort Public Static voidSortint[] arr) { //Arrays.sort (arr); for(inti = 0; i < arr.length; i++) { for(intj = i+1; J < Arr.length; J + +) { if(arr[i]>Arr[j]) { inttemp =Arr[i]; Arr[i]=Arr[j]; ARR[J]=temp; } } } }
Source
Insert new number and reorder