2021-03-24

package eduxcdq;

import java.util.Arrays;

import java.util.Scanner;

public class C032405 {

public static void main(String[] args) {

System.out.println("请输入你要排序的数组的长度");

        Scanner scanner =new Scanner(System.in);

        int length = scanner.nextInt();

        int [] scores =new int[length];

        for (int i=0; i

System.out.println("请输入第"+i+"个元素的值");

            scores[i] = scanner.nextInt();

        }

Arrays.sort(scores,0, length-1);

        for (int i=0; i

System.out.println(scores[i]+"\t");

        }

System.out.println("请输入你要插入的新值:");

        int value = scanner.nextInt();

        int index =0;

        for (int i=0 ; i

if (value

index=i;

                System.out.println("要插入的新元素的位置:"+index);

            }

}

for (int i=index; i

System.out.println("把"+i+"位置的元素"+scores[i]+"移动到"+(i)+"位置"+scores[i]);

                    scores[i] = scores[i-1];

                }

scores[index ]  =value;

                for (int i=0 ; i

System.out.println(scores[i]+"\t");

                }

}

}

你可能感兴趣的:(2021-03-24)