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("請輸入你要排序的數(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");

? ? ? ? ? ? ? ? }

}

}

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • package edu.xcdq; public class Demo05 { public static voi...
    CHJ閱讀 154評論 0 1
  • 練習題1: 請幫小明同學設計一個程序,輸入上次考試成績(int)和本次考試成績(int),然后輸出成績提高的百分...
    炫小狼閱讀 5,284評論 1 3
  • 基本數(shù)據(jù)結構中,數(shù)組是很重要的,這篇小猿圈加加對數(shù)組詳解一席,具體使用,在學習過程中有困惑的朋友,可以看一下加加的...
    小猿圈加加閱讀 504評論 0 0
  • 1、給你一個由若干 0 和 1 組成的字符串s,請你計算并返回將該字符串分割成兩個子字符串(即左子字符串和右子字符...
    前半生不怕閱讀 353評論 0 0
  • package xuhao; public class XUHAOX { public static void m...
    御史大夫01閱讀 89評論 0 1

友情鏈接更多精彩內(nèi)容