-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mergearray.java
105 lines (82 loc) · 3.15 KB
/
Mergearray.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package arrayPrograms;
import java.util.Arrays;
public class Mergearray {
public static void main(String[] args) {
// TODO Auto-generated method stub
/* // array which should be merged
int src1[] = {10, 20, 30, 40, 50};
int src2[] = {9, 18, 27, 36, 45};
// create new array
int newArray[] = new int[src1.length + src2.length];
// Copy first to new array from 0 to src1.length
for(int i=0; i<src1.length; i++) {
newArray[i] = src1[i];
}
// copy second array to new array
for(int i=0, j=src1.length; j<(src1.length + src2.length);
j++, i++) {
newArray[j] = src2[i];
}
// display all array
System.out.println("Array1 = " + Arrays.toString(src1));
System.out.println("Array2 = " + Arrays.toString(src2));
System.out.println("Merged Array = "
+ Arrays.toString(newArray));
}
}*/
/*
// array which should be merged
int src1[] = {10, 20, 30, 40, 50};
int src2[] = {9, 18, 27, 36, 45};
// create new array
int newArray[] = new int[src1.length + src2.length];
// Copy first to new array from 0 to src1.length
System.arraycopy(src1, 0, newArray, 0, src1.length);
// copy second array to new array
System.arraycopy(src2, 0, newArray, src1.length, src2.length);
// display all array
System.out.println("Array1 = " + Arrays.toString(src1));
System.out.println("Array2 = " + Arrays.toString(src2));
System.out.println("Merged Array = "
+ Arrays.toString(newArray));
}
}
*/
/*
// array which should be merged
String src1[] = {"Java", "Python", "C++"};
String src2[] = {"HTML", "CSS", "JavaScript"};
// create new array
String newArray[] = new String[src1.length + src2.length];
// Copy first to new array from 0 to src1.length
System.arraycopy(src1, 0, newArray, 0, src1.length);
// copy second array to new array
System.arraycopy(src2, 0, newArray, src1.length, src2.length);
// display all array
System.out.println("Array1 = " + Arrays.toString(src1));
System.out.println("Array2 = " + Arrays.toString(src2));
System.out.println("Merged Array = "
+ Arrays.toString(newArray));
}
}
*/
/*
// array which should be merged
int src1[] = {10, 20, 30, 40, 50};
int src2[] = {9, 18, 27, 36, 45};
// create new array
int newArray[] = new int[src1.length + src2.length];
// Copy first to new array from 0 to src1.length
System.arraycopy(src1, 0, newArray, 0, src1.length);
// copy second array to new array
System.arraycopy(src2, 0, newArray, src1.length, src2.length);
// sort new array
Arrays.sort(newArray);
// display all array
System.out.println("Array1 = " + Arrays.toString(src1));
System.out.println("Array2 = " + Arrays.toString(src2));
System.out.println("Merged Array = "
+ Arrays.toString(newArray));
}
}
*/