//wap to find set intersection in Java
import java.util.*;class Intersection_Eg
{
public static void main(String[] arg)
{
int A[]=new int[20];
int B[]=new int[20];
int C[]=new int[50];
int m,n,k,i,j;
Scanner s=new Scanner(System.in);
System.out.println("Enter Number of Elements of First Set :");
m=s.nextInt();
System.out.println("Enter Number of Elements of Second Set :");
n=s.nextInt();
System.out.println("Enter the Elements in First Set :");
for (i=0;i<m;i++)
A[i]=s.nextInt();
System.out.println("Enter the Element of Second Set :");
for (i=0;i<n;i++)
B[i]=s.nextInt();
k=0;
for(i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
if (A[i]==B[j])
{
C[k]=A[i];
k++;
}
}
}
System.out.println("Intersection of A and B Sets are : ");
System.out.println("--------------------");
for(i=0;i<k;i++)
System.out.println(C[i]+"\t");
}
}