-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.java
94 lines (89 loc) · 1.64 KB
/
common.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
import java.util.*;
class common{
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
int i,j;
System.out.println("Enter number of elements in array: ");
int n = in.nextInt();
int k=0,len=0;
int f[]= new int[n];
int l=0,len1=0;
int a[]= new int[n];
int b[] = new int[n];
int c[]= new int[n];
System.out.println("Enter elements in array 1:");
for(i=0;i<n;i++)
a[i] = in.nextInt();
System.out.println("Enter elements in array 2:");
for(i=0;i<n;i++)
b[i] = in.nextInt();
System.out.println("Enter elements in array 3:");
for(i=0;i<n;i++)
c[i] = in.nextInt();
//sort
for(i=0;i<n;i++){
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<n;i++){
for(j=0;j<n-i-1;j++)
{
if(b[j]>b[j+1])
{
int temp;
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
for(i=0;i<n;i++){
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
int temp;
temp=c[j];
c[j]=c[j+1];
c[j+1]=temp;
}
}
}
int r[]=new int[n];
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(a[i]==b[j])
{r[k]=a[i];
k++;
len++;}
}}
if(len==0)
System.out.println("No elements match");
else
{
for(i=0;i<n;i++)
{
for(j=0;j<len;j++){
if(c[i]==r[j]){
f[l]=c[i];
l++;
len1++;
}
}
}}
if(len1==0)
System.out.println("No elements match.");
else
{System.out.println("Matches are: ");
for(i=0;i<len1;i++)
System.out.println(f[i]);}
}
}