-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyArray.java
More file actions
31 lines (22 loc) · 828 Bytes
/
CopyArray.java
File metadata and controls
31 lines (22 loc) · 828 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
package array;
public class CopyArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
//6. Write a function to copy an array to another array
int a[] = { 1, 8, 3 };
// Create an array b[] of same size as a[]
int b[] = new int[a.length];
// Copy elements of a[] to b[]
for (int i = 0; i < a.length; i++)
b[i] = a[i];
// Change b[] to verify that
// b[] is different from a[]
b[0]++;
System.out.println("Contents of a[] ");
for (int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println("\n\nContents of b[] ");
for (int i = 0; i < b.length; i++)
System.out.print(b[i] + " ");
}
}