-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathCommon3.java
53 lines (52 loc) · 1.41 KB
/
Common3.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;
/**
* @date 30/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class Common3 {
public static void findcommon(int a[],int b[],int c[])
{
int i=0,j=0,k=0;
while(true)
{
if(a[i]==b[j] && b[j]==c[k])
System.out.print(a[i]+" ");
if(a[i]<b[j])
i++;
else if(b[j]<c[k])
j++;
else
k++;
if(i==a.length || j==b.length || k==c.length)
break;
}
}
public static void main(String []args)
{
int n,m,k,i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter size of first array ");
n=sc.nextInt();
int a[]=new int[n];
for(i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println("Enter size of second array ");
m=sc.nextInt();
int b[]=new int[m];
for(i=0;i<m;i++)
b[i]=sc.nextInt();
System.out.println("Enter size of third array ");
k=sc.nextInt();
int c[]=new int[k];
for(i=0;i<k;i++)
c[i]=sc.nextInt();
System.out.println("Common elements are ");
findcommon(a,b,c);
}
}