Question: This is my RandomIntegerArrayCreator class: import java.util.*; class RandomIntegerArrayCreator{ int[] arr; RandomIntegerArrayCreator(){ Random r = new Random(); // It will generate a number between 0-15
This is my RandomIntegerArrayCreator class:
import java.util.*; class RandomIntegerArrayCreator{ int[] arr; RandomIntegerArrayCreator(){ Random r = new Random();
// It will generate a number between 0-15 int size = r.nextInt(16); arr = new int[size]; for(int i=0;i // It will generate a number between 0-10 arr[i] = r.nextInt(11); } } public int getArraySize(){ return this.arr.length; } public int[] getArray(){ return this.arr; And this is the start of my CommonElements class: class CommonElements{ public static void main(String[] args) { RandomIntegerArrayCreator arrayA = new RandomIntegerArrayCreator(); RandomIntegerArrayCreator arrayB = new RandomIntegerArrayCreator(); } } I need to add code to the CommonElements class to 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), and display the results in the following way. 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 Number of common elements in A and B: 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
