数组的排序
public class Demo14 {
public static void main(String[] args) {
int[] arr = {4,1,5,3,2,9};
//排序前:
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
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;
}
}
}
//排序后:
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}