-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb7.java
More file actions
63 lines (56 loc) · 1.28 KB
/
Copy pathb7.java
File metadata and controls
63 lines (56 loc) · 1.28 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
57
58
59
60
61
62
63
import java.util.Scanner;
public class b7 {
public static void main(String[] args)
{
Scanner sc=new Scanner (System.in);
int n, m;
System.out.println("Enter the size of arrays");
n=sc.nextInt();
m=sc.nextInt();
System.out.println("first array :");
int []arr1=new int[n];
int [] arr2=new int[m];
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Second array:" );
for(int i=0;i<m;i++)
{
arr2[i]=sc.nextInt();
}
int [] arr3=new int[m+n];
int i=0,j=0,k=0;
while(i<n&&j<m)
{
if(arr1[i]<arr2[j])
{
arr3[k]=arr1[i];
k++;
i++;
}
else
{
arr3[k]=arr2[j];
k++;
j++;
}
}
while(i<n)
{
arr3[k]=arr1[i];
i++;
k++;
}
while(j<m)
{
arr3[k]=arr2[j];
j++;
k++;
}
for(int l=0;l<n+m;l++)
{
System.out.print(arr3[l]+" ");
}
}
}