------ array java learning the next day, through the array

Package DATA2;
 Import java.util.Arrays; // import standard library 
public  class DATA2 {
     public  static  void main (String [] args) {
         int [] = {NS. 1, 16, 10, 16, 66 };
         // for often used to cycle through the array 
        for ( int I = 0; I <ns.length; I ++ ) { 
            System.out.println (NS [I]); 
        } 
        / * the Java also provides another for each loop 
         * for each loop through all possible to "iterations may be" data type 
         * will be described later including List, Map, etc. 
         * / 
        for ( int n-: NS) { 
            System.out.println (n-);
        } 
        // the Java standard library provides Arrays.toString (), the content can quickly print array 
        System.out.println (of Arrays.toString (NS));
         // bubble sort 
        for ( int I = 0; I <ns.length -. 1; I ++ ) {
             for ( int J = 0; J <ns.length - I -. 1; J ++ ) {
                 IF (ns [J]> ns [J +. 1 ]) {
                     // exchange ns [J] ns and [+ J. 1]: 
                    int tmp = NS [J]; 
                    NS [J] = NS [J +. 1 ]; 
                    NS [J + 1'd] = tmp; 
                } 
            } 
        } 
        System.out.println (of Arrays.toString (NS));
        // call Arrays.sort JDK provided () can be sorted 
        Arrays.sort (NS); 
        System.out.println (of Arrays.toString (NS)); 
        // the length of each array element does not require a two-dimensional array same 
        int [] [] NT = { 
                { . 1, 2,. 3,. 4 }, 
                { . 5,. 6 }, 
                { . 7,. 8,. 9 } 
            }; 
        // print a two-dimensional array, may be used for two nested loop 
        for ( int [] ARR: NT) {
             for ( int n-: ARR) { 
                of System.out.print (n-); 
                of System.out.print ( ); 
            }','
            System.out.println (); 
        } 
        // or use the Java standard library Arrays.deepToString () 
        System.out.println (Arrays.deepToString (NT)); 
        
    } 
}

Guess you like

Origin www.cnblogs.com/good-hair/p/12128275.html