哪里出问题了 结果不对啊
public class Select {
public static void main(String[] args) {
int[] arr = { 44, 8, 4, 56, 21, 42,555,1 };
System.out.print("排序前:[");
array(arr);
System.out.print("排序后2:[");
arraySelect(arr);
array(arr);
}
public static void arraySelect(int[] arr) {
for (int j = 0; j < arr.length-1; j++) {
for (int i = 0; i < arr.length; i++) {
if (arr[j] > arr[i]) {
int temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
}
public static void array(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
System.out.print(arr[i] + "]\n");
} else
System.out.print(arr[i] + ",");
}
}
} |
|