package eduxcdq;
import java.util.Arrays;
import java.util.Scanner;
public class C032405 {
public static void main(String[] args) {
System.out.println("請輸入你要排序的數(shù)組的長度");
? ? ? ? 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");
? ? ? ? ? ? ? ? }
}
}