最近写了一个Java的冒泡排序方法,供大家参考
public class a{
public static void main(String[] args){
int[] a={6,5,4,3,2,1};
for (int x=0;x<a.length ;x++ )
{
System.out.print(a[x]);
}
System.out.println();
for (int i=a.length;i>=0 ;i-- ){
for (int j=0;j<i-1 ;j++ ){
if (a[j]>a[j+1]){
int b;
b=a[j];
a[j]=a[j+1];
a[j+1]=b;
}
}
}
for (int x=0;x<a.length ;x++ ){
System.out.print(a[x]);
}
}
}