package com.itheima.task;
public class Task9 {
public static void main(String[] args) {
//需求:定义一个方法copyOf(int[] arr, int newLength)
//功能:将数组arr中的newLength个元素拷贝到新数组中,并将新数组返回,从索引为0开始
int[] arr = {11,22,33,44,55,66,77,88,99};
int[] brr = copyOf(arr,5);
for (int i = 0; i < brr.length; i++) {
System.out.print(brr[i] + " ");
}
}
public static int[] copyOf(int[] arr, int newLength){
int[] brr = new int[newLength];
for (int i = 0; i < newLength; i++) {
brr[i] = arr[i];
}
return brr;
}
}
需求:定义一个方法copyOf(int[] arr, int newLength) 功能:将数组arr中的newLength个元素拷贝到新数组中,并将新数组返回,从索引为0开始
最新推荐文章于 2024-07-19 19:11:19 发布