public static void main(String[] args) {
int [] scoreList = new int[5];
scoreList[0] = 68;
scoreList[1] = 78;
scoreList[2] = 88;
scoreList[3] = 98;
scoreList[4] = 58;
/*
*1: 创建新的数组。长度是原来的1.5倍。
*2:依次取出原来数组的元素。取出放到新数组里
*/
int [] newList = new int[7];
// for(int i:scoreList ) {
// newList[]= i;
// }
// for(int i =0;i<scoreList.length;i++) {
// newList[i] = scoreList[i];
// }
for(int i :newList) {
System.out.println(i);
}
System.arraycopy(scoreList, 0, newList, 0, 3);
for (int i : newList) {
System.out.println(i);
}
}
}
原文地址:https://www.cnblogs.com/lipeitong/p/11053096.html
时间: 2024-10-09 16:56:58