Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago