import java.util.*;
public class Splitting
{
public static void main(String[] args)
{
int n,j,i;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for (i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
for (j = 0;j <n;j++)
{
b[j] = sc.nextInt();
}
for(i=0;i<a.length;i++)
{
for(j=0;j<b.length;j++)
{
if(a[i]==b[j])
System.out.println("common elements are;"+a[i]+" ");
}
}
}
}
i/p: 5
1 2 3 4 5
2 8 7 1 5
o/p:
common elements are: 1
common elements are: 2
common elements are: 5
public class Splitting
{
public static void main(String[] args)
{
int n,j,i;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for (i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
for (j = 0;j <n;j++)
{
b[j] = sc.nextInt();
}
for(i=0;i<a.length;i++)
{
for(j=0;j<b.length;j++)
{
if(a[i]==b[j])
System.out.println("common elements are;"+a[i]+" ");
}
}
}
}
i/p: 5
1 2 3 4 5
2 8 7 1 5
o/p:
common elements are: 1
common elements are: 2
common elements are: 5
No comments:
Post a Comment