Bubble Sort - The arithmetic always queried by interviewer

/**
 * 
 * @author tanglei
 * @since  07.27
 */

public class MaoPao {
	public static void main(String[] args){
	    int a[] = {5,4,3,2,1} ;
	    for(int i=0;i<a.length;i++)
	    { 
	       for(int j=0;j<a.length-i-1;j++)
	       {
	          int temp;
	          if(a[j]>a[j+1])
	          {
	             temp  = a[j];
	             a[j] = a[j+1];
	             a[j+1]  = temp;
	          }
	       }    
	    }
	    for(int k=0;k<a.length;k++)
	    {
	    	 System.out.println(a[k]);
	    }
	}

}

    Output :

                   1

                   2

                   3

                   4

                   5

你可能感兴趣的:(J#)