-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyArray.java
More file actions
35 lines (28 loc) · 1003 Bytes
/
CopyArray.java
File metadata and controls
35 lines (28 loc) · 1003 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
34
35
package jxh;
import java.util.Scanner;
public class CopyArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of Elements: ");
int elements = sc.nextInt();
int[] array = new int[elements];
System.out.println("Enter the Array Elements: ");
for (int i = 0; i < elements; i++) {
array[i] = sc.nextInt();
}
int[] copy = new int[elements];
for (int i = 0; i < elements; i++) {
copy[i] = array[i];
}
System.out.println("Original Array:");
for (int i = 0; i < elements; i++) {
System.out.print(array[i] + "\t");
}
System.out.println();
System.out.println("Copy of the Array:");
for (int i = 0; i < elements; i++) {
System.out.print(copy[i] + "\t");
}
System.out.println();
}
}