public class bubblesort {
public static void main(String[] args) {
int[] a = {25,24,12,76,101,96,28};
System.out.println("冒泡排序前 :");
printArray(a);
printbubble(a);
System.out.println("冒泡排序后: ");
printArray(a);
}
public static void printArray(int []a) {
for(int i=0;i<7;i++)
{
System.out.println(a[i]+" ");
}
System.out.println("\n");
}
public static void printbubble(int []a) {
for(int i=0;i<7;i++) {
for(int j=0;j<6-i;j++) {
if(a[j]>a[j+1]) {
int temp = a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
System.out.println("第"+(i+1)+"次排序后: ");
printArray(a);
}
}
}