Skip to content

Commit 051cad6

Browse files
authored
CopyArray Elements
1 parent b0225b7 commit 051cad6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

CopyArray

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class CopyArray {
2+
public static void main(String[] args) {
3+
//Initialize array
4+
int [] arr1 = new int [] {1, 2, 3, 4, 5};
5+
//Create another array arr2 with size of arr1
6+
int arr2[] = new int[arr1.length];
7+
//Copying all elements of one array into another
8+
for (int i = 0; i < arr1.length; i++) {
9+
arr2[i] = arr1[i];
10+
}
11+
//Displaying elements of array arr1
12+
System.out.println("Elements of original array: ");
13+
for (int i = 0; i < arr1.length; i++) {
14+
System.out.print(arr1[i] + " ");
15+
}
16+
17+
System.out.println();
18+
19+
//Displaying elements of array arr2
20+
System.out.println("Elements of new array: ");
21+
for (int i = 0; i < arr2.length; i++) {
22+
System.out.print(arr2[i] + " ");
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)