冒泡排序
//使用Java中的数组程序进行泡泡排序
public class BubbleSort {
static int[] a = {6,4,5,2,3,1};
public static void main(String[] args) {
sort(a);
display();
}
public static void sort(int[] a){
int length = a.length;
for(int i=0;i<length-1;i++){
for(int j=0;j<length-1-i;j++){
if(a[j]>a[j+1]){
int temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
public static void display(){
for(int i:a){
System.out.print(i+" ");
}
}
}