public class Maopao {
// 初始化数组的数据
private static int al[] = { 5, 9, 6, 7, 8, 10, 4, 3, 2, 1 };
public static void main(String[] args) {
System.out.println("------------排序前-------------");
show();
//System.out.println("------------排序中-------------");
for (int i = 0; i < al.length; i++) {
for (int j = 0; j < al.length - i - 1; ++j) {
if (al[j] > al[j + 1]) {//倒序就是把'>'改成'<'
int temp = al[j];
al[j] = al[j + 1];
al[j + 1] = temp;
//show();
}
}
}
System.out.println("------------排序后-------------");
show();
}
// 显示数组的所有数据
private static void show() {
for (int i : al) {
System.out.print("[" + i + "]");
}
System.out.println();
}
}