package com.yingyong.day13;

public class SecondSort {

public static void main(String[] args) { // TODO Auto-generated method stub int [] a = new int[] {89,72,66,54,39,21}; int i,j,t,k; System.out.print("排序前:"); for(i = 0;i < a.length;i++) { System.out.print(a[i] + " "); } System.out.println(); //比较交换法排序 for(i = 0;i < 5;i++) { t = i; for(j = i + 1;j < 6;i++) { if(a[j] < a[t]) { t = j;
} } if(t !=i) { //判断a[i]是否已经是本轮最小元素 k = a[i]; a[i] = a[t]; a[t] = k; } } System.out.print("排序后:"); for(i = 0;i < a.length;i++) { System.out.print(a[i] + " ");
} System.out.println(); } } 结果:排序前:89 72 66 54 39 21