public class Test {
public static void main(String[] args) {
int[] arr1 = new int[5];
int[] arr2 = new int[5];
// 初始化数组
for (int i = 0; i < 5; i++) {
arr1[i] = i;
arr2[i] = i + 3;
}
// 输出复制前两个数组
System.out.println("\n复制前两个数组: ");
for (int i = 0; i < 5; i++) {
System.out.print(arr1[i] + " ");
}
System.out.println();
for (int i = 0; i < 5; i++) {
System.out.print(arr2[i] + " ");
}
// arr1 0~3复制到arr2
for (int i = 0; i < 4; i++) {
arr2[i] = arr1[i];
}
System.out.println("\n复制后两个数组: ");
// 输出复制后两个数组
for (int i = 0; i < 5; i++) {
System.out.print(arr1[i] + " ");
}
System.out.println();
for (int i = 0; i < 5; i++) {
System.out.print(arr2[i] + " ");
}
}
}