Java 數組 之 一維數組 追加 元素

來源:互聯網
上載者:User

標籤:www.   增強for迴圈   引用   地址   pre   添加   out   維數   增強   

http://www.verejava.com/?id=16992650730025

/*數組分類1. 一維數組    1.1 一維數組的定義和初始化    1.2 對一維數組的操作, 遍曆,添加,插入,修改,刪除,排序,尋找2. 二維數組    2.1 二維數組的定義和初始化    2.2 二維數組的遍曆3. 多維陣列4. 增強for迴圈*/public class ArrayAppend{    public static void main(String[] args)    {        //一維數組的定義和初始化        //靜態定義一維數組        int[] scores={90,70,50,80,60,85};                        //向一維數組scores末尾中添加一個學生的成績 75.        /*        思路:            1. 先建立一個比原來scores數組長度大1的臨時數組 tempArray            2. 將scores數組的每一個值複製到 tempArray            3. 然後將 成績為 75 賦值到 tempArray的新增最後的索引位置            4. 最後將tempArray地址指標引用賦值給 scores;        */        int[] tempArray=new int[scores.length+1];        for(int i=0;i<scores.length;i++)        {            tempArray[i]=scores[i];        }        tempArray[scores.length]=75;        scores=tempArray;        //列印輸出添加75成績後的scores        for(int i=0;i<scores.length;i++)        {            System.out.print(scores[i]+",");        }    }}

http://www.verejava.com/?id=16992650730025

Java 數組 之 一維數組 追加 元素

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.