-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary search.java
More file actions
38 lines (30 loc) · 1.34 KB
/
binary search.java
File metadata and controls
38 lines (30 loc) · 1.34 KB
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
36
37
38
import java.util.Scanner;
public class ArrayCopyExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter the size of the array
System.out.print("Enter the size of the array: ");
int size = scanner.nextInt();
// Create the source array with the specified size
int[] sourceArray = new int[size];
// Prompt the user to enter the elements of the array
System.out.println("Enter " + size + " elements for the array:");
for (int i = 0; i < size; i++) {
System.out.print("Element " + (i + 1) + ": ");
sourceArray[i] = scanner.nextInt();
}
// Create a destination array with the same length as the source array
int[] destinationArray = new int[sourceArray.length];
// Copy the contents of the source array to the destination array
for (int i = 0; i < sourceArray.length; i++) {
destinationArray[i] = sourceArray[i];
}
// Print the contents of the destination array to verify the copy
System.out.println("Contents of the destination array:");
for (int i = 0; i < destinationArray.length; i++) {
System.out.print(destinationArray[i] + " ");
}
// Close the scanner
scanner.close();
}
}