章节习题-使用冒泡排序
class TwoDimensionalArray {
public static void main(String[] args) {
int arr[] = new int[]{11,99,54,32,14};
int eg;
System.out.println("======原始数组======");
for(int i = 0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}
//由小到大 冒泡排序
for(int i = 0; i < (arr.length - 1); i++){ //外层循环,总循环几次
for(int j = 0; j < (arr.length - 1 - i); j++){ //内层循环,每一次大循环中有多少次循环(比较次数)
if(arr[j + 1] < arr[j]){
eg = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = eg;
}
}
}
System.out.println("/n======冒泡排序后(由小到大)======");
for(int i = 0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}
}
}