copyOf數組復制方法的使用(數組擴容練習)
阿新 • • 發佈:2019-04-21
sta system util copy public class and stat pyo
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(); } privatestatic 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)); } }
copyOf數組復制方法的使用(數組擴容練習)