Question: This is my RandomIntegerArrayCreator: import java.util.*; class RandomIntegerArrayCreator{ int [] arr; RandomIntegerArrayCreator(){ Random r = new Random(); int size = r.nextInt(16); arr = new int[size];

This is my RandomIntegerArrayCreator:

import java.util.*;

class RandomIntegerArrayCreator{ int [] arr; RandomIntegerArrayCreator(){ Random r = new Random(); int size = r.nextInt(16); arr = new int[size]; for (int i=0; i

Write a class called CommonElements with a single method main that will:

  • Create and obtain two integer arrays (arrayA and arrayB) using RandomIntegerArrayCreator type objects and its methods,

  • find the number of common elements between arrayA and arrayB (say: if integer 2 appears in arrayA once and twice in arrayB, that counts as ONE common element between the two),

  • display the result using the format shown below (see Sample Output box).

  • Hint: You can use additional array(s) to keep track of/count

Sample Output:

Array A: 2 3 1 0 1 5

Array B: 4 3 4 0 5 2 1 2 2 5

Element: # in A: # in B:

0 1 1

1 2 1

2 1 3

3 1 1

5 1 2

If there are no common elements (or one or two arrays are empty), just display:

Number of common elements in A and B: 0

Number of common elements in A and B: 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!