class BubbleSort
{
public static void main(String[] args)
{
System.out.println("选择排序前的数组是:");
int[] arr = {26,26,0,48,26,1584,6,3};
for(int a:arr)
{
System.out.print(a+" ");
}
sort(arr);
System.out.println();
System.out.println("选择排序后的数组是:");
for(int a:arr)
{
System.out.print(a+" ");
}
}
public static void sort(int[] a)
{
for(int i =0;i<a.length-1;i++)
{
for(int j=0;j<a.length-i-1;j++)
{
if(a[j]>a[j+1])
{
int num = a[j+1];
a[j+1] = a[j];
a[j] = num;
}
}
}
}
} |