public static void main(String args[]){
int[] num = new int[]{4,3,2,5,55,33,566,8,99};
for(int y = 0; y < num.length - 1; y++){
for(int x = 0; x < num.length - 1; x++){
if(num[x] > num[x + 1]){
int t = num[x];
num[x] = num[x + 1];
num[x + 1] = t;
}
}
}
print(num);
}
public static void print(int[] temp){
for(int x : temp){
System.out.print(x + "_");
}
}
直接撸代码吧,记住一个变量,两次循环,三次赋值,完美解决。