-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathass20.java
More file actions
39 lines (34 loc) · 1.41 KB
/
Copy pathass20.java
File metadata and controls
39 lines (34 loc) · 1.41 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
public class ass20 {
public static void main(String[] args) {
int[] firstArray = {1, 2, 3, 4, 5};
int[] secondArray = {6, 7, 8, 9, 10};
int[] mergedArray = new int[firstArray.length + secondArray.length];
// Copy elements of firstArray to mergedArray
for (int i = 0; i < firstArray.length; i++) {
mergedArray[i] = firstArray[i];
}
// Copy elements of secondArray to mergedArray
for (int i = 0; i < secondArray.length; i++) {
mergedArray[firstArray.length + i] = secondArray[i];
}
System.out.print("First Array = {");
for (int i = 0; i < firstArray.length; i++) {
System.out.print(firstArray[i]);
if (i < firstArray.length - 1) System.out.print(", ");
}
System.out.println("}");
System.out.print("Second Array = {");
for (int i = 0; i < secondArray.length; i++) {
System.out.print(secondArray[i]);
if (i < secondArray.length - 1) System.out.print(", ");
}
System.out.println("}");
// Display merged array
System.out.print("Merge two Array Elements = {");
for (int i = 0; i < mergedArray.length; i++) {
System.out.print(mergedArray[i]);
if (i < mergedArray.length - 1) System.out.print(", ");
}
System.out.println("}");
}
}