Write a java program to print intersection elements of both the array
int arr1[] = {1, 2, 2, 1};
int arr2[] = {2};
class Intersection
{
public static void main(String args[])
{
int arr1[] = {1, 2, 2, 1};
int arr2[] = {2};
System.out.println(“Intersection of 2 arrays”);
for(int i=0;i< arr1.length; i++)//i=1; 1<4;
{
for(int j=0;j< arr2.length;j++)//j=0; 0<1
{
if(arr[i]==arr[j])//2==2
{
System.out.println(arr1[i]+ ” “);//2
arr2[j]=-1;//-1
break;
}
}
}
}}