import java.util.Random;
public class BubbleSort{
public static void main(String[] args){
int[] ints = arrGet(20, 100,0);
bubbleSort(ints);
}
public static int[] arrGet(int ArrLength, int RandLength, int p) {
int[] x = new int[ArrLength];
for (int i=0;i < x.length;i++){
int nextInt = new Random().nextInt(RandLength);
x[i] = nextInt;
}
if (p == 1){
printArray(x);
}
return x;
}
public static void printArray(int[] arr) {
for (int y = 0; y < arr.length; y++) {
System.out.print(arr[y] + " ");
}
System.out.println("\n");
}
public static void bubbleSort ( int[] arr){
for (int i = 0;i < arr.length-1;i++){
for (int x=0;x<arr.length-1;x++){
if (arr[x]>arr[x+1]){
int temp = arr[x];
arr[x] = arr[x+1];
arr[x+1] = temp;
}
}
System.out.println("第" + i + "次排序后");
printArray(arr);
}
}
}