Java array of common methods and sorting

Package com.yuan; 

Import java.util.Arrays; 

public  class Practise1 { 
    
    
    public  static  void main (String [] args) {
         // Array 
    
        String [] ST2; 
        ST2 = new new String [. 4 ]; 
        String ST3 [] = { " KD "," 38dj " }; 
        String ST4 [] = new new String [] {" 123 "," YUI "," 2k3j " }; 
        
        // dimensional array 
        int T1 [] [] = {{. 1, 3,5 }, {23, 44 }};
         int T0 [] = {. 1, 2,. 3 };
         // replace array elements
        Arrays.fill (T0,. 9 ); 
        Arrays.fill (T0, 0,. 1, 100 ); 
        System.out.println (T0 [ 0 ]);
         // tuples sorted 
        int T4 [] = {5,3,0 , 12,9 }; 
        Arrays.sort (T4); 
        Arrays.sort (ST3); 
        System.out.println (T4 [ 0]); // change the original array 
        System.out.println (st3 [0]) ; // the sorted order dictionaries
         // replicon membered 
        int named new1 [] = Arrays.copyOf (T4,. 3 );
         int to new2 [] = Arrays.copyOfRange (T4, 2,. 9 ); 
        System.out.println ( new1 [ "?" 0] + );
        System.out.println (to new2 [ 0] + "?" );
         // array query 
        int shuju [] = {33 is, 2, 44 is,. 1, 0 }; 
        Arrays.sort (shuju); // if there is no sort the result is uncertain if there is more than the specified element can not be guaranteed to find which one 
        int index1 = Arrays.binarySearch (shuju, 2); // Ruoguo key search returns the index in the array, otherwise -1 or "-" (insertion point) 
        int index2 = Arrays.binarySearch (shuju, 2,5, 10 );
         int T2 [] [] = new new  int [2] [. 4 ]; 
        T2 [ 0] [0] = 12 is ; 
         for ( int I = 0; I <t2.length; I ++ ) {
             for ( int j=0; j<t2[i].length; j++){
                System.out.print(t2[i][j]);
            }
            System.out.println();
        }
        
        
        //排序算话
        //冒泡算法
        int shuzu[] = {12,80,1,14,9,28};
        for(int i=1;i<shuzu.length;i++){
            for(int j=0;j<shuzu.length-i;j++){
                int temp;
                if(shuzu[j]>shuzu[j+1])    {
                    temp=shuzu[j];
                    shuzu[j]=shuzu[j+1];
                    Shuzu [j +1] = temp; 
                } 
            } 
        } 
        System.out.println (Shuzu [ 5 ]); 
        
        // directly选择Sort 
        for ( int i = 1; i <Shuzu.Length; i ++ ) {
             int index = 0 ;
             for ( int j = 1; j <Shuzu.Length-i; j ++ ) {
                 an if (Shuzu [j]> Shuzu [index]) { 
                    index = j; 
                } 
                int temp = Shuzu [Shuzu.Length- i]; 
                Shuzu [ shuzu.length-i] = Shuzu [index]; 
                Shuzu [index] = temp; 
            } 
        } 
        System.out.println (Shuzu [ 5 ]); 
        
        // anti转排mechanism 
        for ( int j = 0; j <(Shuzu.Length) / 2; j ++ ) {
             int temp;
             an if (Shuzu [j]> Shuzu [j + 1 ]) { 
                temp = Shuzu [j]; 
                Shuzu [j] = Shuzu [(Shuzu.Length) / 2-1- j]; 
                Shuzu [(Shuzu.Length) / 2-1-j] = temp; 
            } 
        } 
        System.out.println (Shuzu [5]);
    }
}

 

Guess you like

Origin www.cnblogs.com/noperx/p/11372565.html