选择排序
/**} * 选择排序 (将小的放在前面,每轮只和第一个数交换) * @author Administrator * */ public class TestArray2 { public static void main(String[] args) { int [] arr = {6,9,3,1,4,8,5,7,2}; for (int i = 0; i < arr.length - 1; i++) { for (int j = i + 1; j < arr.length; j++) { if (arr[i] > arr[j]) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } printArr(arr); } public static void printArr(int[] arr) { for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }