[java]代码库
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[10];
for (int i = 0; i < arr.length - 1; i++) {
arr[i] = new Random().nextInt(100);
}
System.out.print("排序之前:");
for (int i : arr) {
System.out.print(i + " ");
}
Arrays.sort(arr);
System.out.println();
System.out.print("排序之后:");
for (int i : arr) {
System.out.print(i + " ");
}
int flag = 0;
System.out.println("\n请输入要插入的数字:");
int a = sc.nextInt();
for (int i = 0; i < arr.length; i++) {
if (a >= arr[i]) {
flag = i;
}
}
for (int i = 1; i <= flag; i++) {
arr[i - 1] = arr[i];
}
arr[flag] = a;
System.out.println("插入之后的数组为:");
for (int i : arr) {
System.out.print(i + " ");
}
}