-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZoho35.java
More file actions
116 lines (108 loc) · 1.41 KB
/
Copy pathZoho35.java
File metadata and controls
116 lines (108 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
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
106
107
108
109
110
111
112
113
114
115
116
import java.util.*;
import java.io.*;
class Zoho35
{
static void merge(int[] arr1 , int[] arr2)
{
int count=0,i,j,max,min;
int flag =0;
int l1 = arr1.length;
int l2 = arr2.length;
for(i=0;i<l1;i++)
{
for(j=0;j<l2;j++)
{
if(arr1[i]==arr2[j])
{
flag = 1;
}
}
if(flag==1)
{
flag = 0;
}
else
{
count++;
}
}
if(l1>l2)
{
max = l1;
min = l2;
}
else{
max= l2;
min=l1;
}
int n1 = (max - min)+count;
int n2 = n1 + min;
int[] arr3 = new int[n2];
for(i=0;i<n2;i++)
{
arr3[i]=0;
}
for(i=0;i<l1;i++)
{
arr3[i] = arr1[i];
}
int k=l1;
for(i=0;i<l2;i++)
{
for(j=0;j<l1;j++)
{
if(arr2[i] == arr1[j])
{
flag = 1;
}
}
if(flag == 0)
{
arr3[k]=arr2[i];
k++;
}
else{
flag=0;
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
if(arr3[i]<arr3[j])
{
int temp = arr3[j];
arr3[j] = arr3[i];
arr3[i] = temp;
}
}
}
System.out.println("MERGED ARRAY ");
for(i=0;i<n2;i++)
{
System.out.println(arr3[i]);
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the numbers in array 1 : ");
int l1 = sc.nextInt();
int[] arr1 = new int[l1];
int i;
System.out.println("Enter the elements of array 1 : ");
for(i=0;i<l1;i++)
{
arr1[i]= sc.nextInt();
}
System.out.println("Enter the numbers in array 2 : ");
int l2 = sc.nextInt();
int[] arr2 = new int[l2];
System.out.println("Enter the elements of array 2 : ");
for(i=0;i<l2;i++)
{
arr2[i]= sc.nextInt();
}
merge(arr1,arr2);
}
}