Java冒泡排序
代码如下:
public static void main(String[] args) {
int [] arr = {1,4, 7, 2, 9, 15, 87, 954, 124};
int temp;
for(int i = 0;i < arr.length-1;i++) {
for(int j =0;j<arr.length-i-1;j++) {
if(arr[j]>arr[j+1]) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for(int j : arr) {
System.out.println(j);
}
}
运行结果:
本文来自博客园,作者:程序员hg,转载请注明原文链接:https://www.cnblogs.com/hg-blogs/p/15465046.html