Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write in Java, 2. (7 pts) Suppose that you and I are friends on social media, and you want to figure out the friends we
Write in Java,
2. (7 pts) Suppose that you and I are friends on social media, and you want to figure out the friends we have in common. One way of doing this would be to treat your friends list as an array and my friends list as another array. Then, the problem of finding our common friends would be solvable by finding the intersection (set of common elements) between those two arrays. Assume that each friend is represented by a unique numerical ID number. Using a person's name directly isn't a good idea, because it's possible for more than one person to have the same name. Within a new class named ArrayIntersection, write a method void intersection(int[] al, int[] a2) that takes two int arrays of ID numbers as parameters. The method should find and display the intersection between those two arrays. The method should also find and display the count of common elements between the two arrays. You can assume that both arrays contain unique elements that is, neither array contains duplicate elements within itself. Hint: For each element of al, perform a linear search of a2. Note the void return type this method does not need to return anything. Just have it print the intersection and the quantity of elements in that intersection. Test your intersection method by calling it from a main method (within the same ArrayIntersection class). You do not need to get any user input just create your test arrays directly within your main methodStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started