对比getArraySort和getArraySort2方法,观察不同点 public class TestArraySort { public static void main(String[] args) { int[] a = new int[]{34,8,64,51,32,21}; int[] a1 = {34,8,64,51,32,21}; int[] returnA = getArraySort2(a); for (int i : returnA) { System.out.println(i+" "); } } public static int[] getArraySort(int[] a){ for(int i=1;i<a.length;i++){ int j; int tmp = a[i]; for(j=i;j>0&&tmp<a[j-1];j--){ a[j] = a[j-1]; } a[j] = tmp; } return a; } public static int[] getArraySort2(int[] a){ for(int i=1;i<a.length;i++){ int j; int tmp = a[i]; for(j=i;j>0;j--){ if(tmp<a[j-1]){ a[j] = a[j-1]; } } a[j] = tmp; } return a; } }