-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsameArray.java
More file actions
27 lines (21 loc) · 759 Bytes
/
sameArray.java
File metadata and controls
27 lines (21 loc) · 759 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
//The program demonstrates that two variable reference the same array
//You cannot copy the array by merely assigning one variable to another
//To copy the array we should copy individual element by using a loop
public class sameArray {
public static void main(String[] args) {
int[] array1={2,4,6,8,10};
int[] array2=array1;
//Change the values
array1[0]=300;
array2[3]=1000;
//display the result
System.out.println("The contents of the first Array ");
for (int value : array1) {
System.out.println(value);
}
System.out.println("The contents of the second Array ");
for (int value:array2) {
System.out.println(value);
}
}
}