-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayCopyTest.java
More file actions
33 lines (28 loc) · 897 Bytes
/
Copy pathArrayCopyTest.java
File metadata and controls
33 lines (28 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* 作者:张启卫
* 时间:2016年9月24号
* 功能:学习java数组的复制
*/
public class ArrayCopyTest {
public static void main(String[] args){
//创建数组
int[] array1 = {1,2,3};
int[] array2 = {4,5,6};
System.out.println("两个数组的初始值为:");
for(int i=0; i<array1.length; i++)
System.out.println("array1["+i+"]=" + array1[i]);
for(int i=0; i<array2.length; i++)
System.out.println("array2["+i+"]=" + array2[i]);
//将array2赋值给array1
array1 = array2;
System.out.println("在执行数组的复制后,两个数组的值:");
for(int i=0; i<array1.length; i++)
System.out.println("array1["+i+"]=" + array1[i]);
for(int i=0; i<array2.length; i++)
System.out.println("array2["+i+"]=" + array2[i]);
System.out.println("将array2的一个元素改变:");
array2[2]=8;
System.out.println("array2[2]=" + array2[2]);
System.out.println("array1[2]=" + array1[2]);
}
}