java实现冒泡排序
前言
记录java实现冒泡排序算法的代码实现
代码实现
public class BubbleSort {
public static void main(String[] args) {
int[] a = {2, 3, 0, 1, 7};
int temp,i,j;
for (i = 0; i < 5 - 1; i++) {
for (j = 0; j < 5 - i - 1; j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j+1]=temp;
}
}
}
for (i = 0; i < 5; i++) {
System.out.println(a[i]);
}
}
}
运行结果
