-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram53.java
More file actions
56 lines (36 loc) · 1.21 KB
/
Copy pathprogram53.java
File metadata and controls
56 lines (36 loc) · 1.21 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Scanner;
public class program53 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// First Array
System.out.print("Enter size of first array: ");
int n1 = sc.nextInt();
int arr1[] = new int[n1];
System.out.println("Enter first array elements:");
for(int i = 0; i < n1; i++) {
arr1[i] = sc.nextInt();
}
// Second Array
System.out.print("Enter size of second array: ");
int n2 = sc.nextInt();
int arr2[] = new int[n2];
System.out.println("Enter second array elements:");
for(int i = 0; i < n2; i++) {
arr2[i] = sc.nextInt();
}
// Merge two arrays
int merge[] = new int[n1 + n2];
for(int i = 0; i < n1; i++) {
merge[i] = arr1[i];
}
for(int i = 0; i < n2; i++) {
merge[n1 + i] = arr2[i];
}
// Display merged array
System.out.println("Merged Array:");
for(int i = 0; i < merge.length; i++) {
System.out.print(merge[i] + " ");
}
sc.close();
}
}