代码实现
import java.util.Arrays;
import java.util.Random;
public class Test_MaoPao {
public static void main(String[] args) {
int[] arr = suiJi();
System.out.println(Arrays.toString(arr));
sort(arr);
System.out.println(Arrays.toString(arr));
}
private static int[] suiJi() {
int n = new Random().nextInt(6) + 5;
int[] arr = new int[n];
for(int i = 0;i<arr.length;i++) {
arr[i] = new Random().nextInt(100);
}
return arr;
}
private static void sort(int[] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = arr.length-1; j >i; j--) {
if( arr[j] < arr[j-1] ) {
int temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
}
}
}
}
}