java数组冒泡排序

public class PaiXu1 {
public static void main(String[] args) {
int[] s = {345,879,456,870,221,902,148,234,478};
System.out.println("排序之前:");
System.out.println(Arrays.toString(s));
System.out.println("排序之后:");
int temp = 0;
for (int i = 0;i < s.length-1;i++){
for (int j = 0;j < s.length-1-i;j++){
if (s[j]>s[j+1]){
temp = s[j];
s[j] = s[j+1];
s[j+1] = temp;
}
}
}
System.out.println(Arrays.toString(s));
}
}

猜你喜欢

转载自www.cnblogs.com/THEONLYLOVE/p/9116970.html