public class kaobei {
public static void main(String[] args) {
int[] arr = {11,22,33};
int[] arr2 = copy(arr);
copy1(arr2);
}
public static void copy1(int[] arr){
System.out.print("[");
for (int i = 0; i < arr.length; i++) {
System.out.print(i ==arr.length-1 ? arr[i]:arr[i] + ",");
}
System.out.print("]");
}
标签:arr,int,打印,System,length,arr2,数组,public From: https://www.cnblogs.com/nulicheng/p/17855753.html
public static int[] copy(int[] arr){
// arr = [11,22,33]
//1.创建arr2与arr一样的长度
int[] arr2 = new int[arr.length];
//arr2 = [0,0,0]
//2.把对应的值赋值给新数组
for (int i = 0; i < arr.length; i++) {
arr2[i] = arr[i];
//arr2 = [11,22,33]
}
return arr2;
}
}