Insert values and performs the sort order

Month.JUL.JUL03 Package; 

Import java.util.Arrays; 
Import java.util.Scanner; 

// Insert values 
public  class Demo02 {
     static Scanner INPUT = new new Scanner (the System. in ); 

    public  static  void main (String [] args ) {
 //         a set of columns: 99,85,82,63,60 
        int [] the nums = { 99 , 85 , 82 , 63 is , 60 , 0 }; 
        the System. OUT .println ( " inserted before the value: " +Of Arrays.toString (the nums));
 //         add a number, the number of columns inserted into it and kept descending 
        the System. OUT .println ( " Enter a number: " );
         int NUM = input.nextInt ();

      int index = nums.length-1; // identifying the insert position (element array index) to a minimum value if the number entered by default in the last

// Find the index to be inserted 
        for ( int I = 0 ; I <nums.length; I ++ ) {
             IF (NUM> the nums [I]) { 
                index = I;
                 BREAK ; // found, exit the loop 
            } 
        } 
        / / all the elements are sequentially moved backward behind an index 
        for ( int I = nums.length - 2 ; I> = index; i-- ) { 
            the nums [I + . 1 ] = the nums [I]; 
        } 
        the nums [index ] = NUM; 
        the System.OUT .println ( " insert the value: " + of Arrays.toString (the nums)); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/zeng1997/p/11125460.html