选择排序
/** * 选择排序 */ public class SelectSort { public static void main(String[] args) { int[] arr = {23, 45, 43, 22, 44, 87, 56, 41}; int temp = 0; for(int i=0; i<arr.length-1; i++){ for(int j=i+1; j<arr.length; j++){ if(arr[i]>arr[j]){ temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } } StringBuilder sb = new StringBuilder(); sb.append("["); for(int i=0; i<arr.length; i++){ if(i == arr.length-1){ sb.append(arr[i]).append("]"); }else { sb.append(arr[i]).append(","); } } System.out.println(sb.toString()); } }