Java數(shù)組中如何刪除scores數(shù)組索引index位置的值,相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。

企業(yè)建站必須是能夠以充分展現(xiàn)企業(yè)形象為主要目的,是企業(yè)文化與產(chǎn)品對外擴(kuò)展宣傳的重要窗口,一個(gè)合格的網(wǎng)站不僅僅能為公司帶來巨大的互聯(lián)網(wǎng)上的收集和信息發(fā)布平臺,成都創(chuàng)新互聯(lián)公司面向各種領(lǐng)域:葡萄架等成都網(wǎng)站設(shè)計(jì)公司、營銷型網(wǎng)站建設(shè)解決方案、網(wǎng)站設(shè)計(jì)等建站排名服務(wù)。
/**
題目: 刪除scores數(shù)組索引index位置的值
思路:
1. 創(chuàng)建一個(gè)臨時(shí)比scores 小1的臨時(shí)數(shù)組tempArray
2. 將index前面的數(shù)據(jù)復(fù)制到tempArray前面
3. 將index后面的數(shù)組依次復(fù)制到 tempArray 后面
4. 將tempArray地址指針引用賦值給 scores
5. 打印輸出scores
*/import java.util.Scanner;public class ArrayDelete {
public static void main(String[] args) { //一維數(shù)組的定義和初始化
int[] scores = { 90, 70, 50, 80, 60, 85 };
System.out.println("請輸入要刪除的索引index :");
Scanner in = new Scanner(System.in); int index = in.nextInt(); //1. 創(chuàng)建一個(gè)臨時(shí)比scores 小1的臨時(shí)數(shù)組tempArray
int[] tempArray = new int[scores.length - 1]; //2. 將index前面的數(shù)據(jù)復(fù)制到tempArray前面
//3. 將index后面的數(shù)組依次復(fù)制到 tempArray 后面
for (int i = 0; i < scores.length; i++) { if (i < index)
tempArray[i] = scores[i]; if (i > index)
tempArray[i - 1] = scores[i];
} //4. 將tempArray地址指針引用賦值給 scores
scores = tempArray; //5.打印輸出scores
for (int i = 0; i < scores.length; i++) {
System.out.print(scores[i] + ",");
}
}
}看完上述內(nèi)容,你們掌握J(rèn)ava數(shù)組中如何刪除scores數(shù)組索引index位置的值的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
當(dāng)前名稱:Java數(shù)組中如何刪除scores數(shù)組索引index位置的值
文章鏈接:http://chinadenli.net/article26/ppdjcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、網(wǎng)站建設(shè)、微信小程序、標(biāo)簽優(yōu)化、App開發(fā)、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)