copyOf数组复制方法的使用(数组扩容练习)

package com.Summer_0420.cn;

import java.util.Arrays;

/**
 * @author Summer
 * 我们使用数组存储了50名学生的考试信息 , 今天又增加了三名同学 , 请扩大存储介质 , 足以存储53名学生信息
 */
public class TestMethod06 {
    static int [] score = new int[50];
    public static void main(String[] args) {
        addScore();

    }
    private static void addScore() {
        for (int i = 0; i < score.length; i++) {
            score[i] =(int) (Math.random()*101);
        }
        System.out.println(Arrays.toString(score));
        
        int [] sc = Arrays.copyOf(score, score.length+3);
        
        System.out.println(Arrays.toString(sc));
    }

}

 

posted @ 2019-04-20 22:46  Geek张东坡  阅读(757)  评论(0编辑  收藏  举报