编写代码
int [] sz = {12,37,18,90,21,54,4};
for (int i=0;i<sz.length;i++) { //外层循环
for (int j=1;j<sz.length;j++) { //内层循环
int num = 0;
//当满足if条件时交换两个数的值
if (sz [j-1] > sz [j]) {
num = sz [j-1];
sz [j-1] = sz [j];
sz [j] = num;
}
}
}
for (int f=0;f<sz.length;f++) {
System.out.println(sz [f]);
}
如图所示
结果展示