Constraints / notes:
Given these two sample arrays (orientation changed for readability):
Array A |
Array B |
2 3 1 0 1 5 |
4 3 4 0 5 2 1 2 2 5 |
Your program output should look like this:
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 Number of common elements in A and B: 5 |
If there are no common elements (or one or two arrays are empty), just display:
Number of common elements in A and B: 0
Test your class with different arrays. Your solution does not need to be efficient, just effective.
import java.util.*;
class RandomIntegerArrayCreator{
int[] arr;
RandomIntegerArrayCreator(){
Random rand = new Random();
// It will generate a number between 0-15
int size = rand.nextInt(16);
arr = new int[size];
for(int i=0;i<size;i++){
// It will generate a number between 0-10
arr[i] = rand.nextInt(11);
}
}
public int getArraySize(){
return this.arr.length;
}
public int[] getArray(){
return this.arr;
}
public static void main(String[] args) {
RandomIntegerArrayCreator r = new
RandomIntegerArrayCreator();
System.out.println("Size = "+r.getArraySize());
int[] arr = r.getArray();
System.out.print("Generated array is ");
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
}
}
Write a class called RandomIntegerArrayCreator that: upon its object instantiation: will generate a random integer arraySize...
Create a new class called DemoSortingPerformacne Create a private method called getRandomNumberArray. It returns an array of Integer and has 2 parameters: arraySize of type int and numberOfDigits of type int. This method should create an array of the specified size that is filled with random numbers. Each random numbers should have the same number of digits as specified in the second parameter In your main method (or additional private methods) do the following: Execute selection sort on quick sort...
The method generate() will produce integer arrays of a random size between 10 and 20 members. The method print() will print out the members of an integer array input. The method insert() will accept two arrays as inputs. It will produce a new array long enough to contain both arrays, and both input arrays should be inserted into the new array in the following manner: select a random member of the first array, and insert every member of the second...
eciare a class to represent sample data set of 150 elements called DataType. DataType has two member vari member functions and include the functions to generate a sample set of random numbers between 81 and 255, maximum value, and the range ables- an integer array and its size. Declare the basic calculate the mean, median, the minimum value, the eciare a class to represent sample data set of 150 elements called DataType. DataType has two member vari member functions and...
C++ please Programming Question 4: Operator Overloading [20 marks] The class SpecialArray represents an array of integers. The class contains two data members: array (of type int"), which represents the array of integers, and size (of type int) that represents the size of the array. The class SpecialArray also overloads the following operators: operator: Compares two arrays. An array "A" is smallerhan an array "B" if the size of array "A" is smaller than the size of "B", or if...
In C... Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise the program...
This question has been answered before, but no codes given as the answer were right. please help. In the mathematical theory of sets, a set is defined as a collection of distinct items of the same type. In some programming languages, sets are built-in data types; unfortunately, this is not the case in C++. However, we can simulate a set using a one-dimensional array. Some operations can be performed on sets. We will consider three(3) of them: union, intersection and...
Write a C program that inputs 5 elements into each of 2 integer arrays. Add corresponding array elements, that array1 [0] + array2[0], etc. Save the sum into a third array called sumArray[]. Display the sum array. Submit your and the input and output of the complete execution.
Write a Java program that does the following. a. Declare an integer 2D array with 5 rows and 5 columns. b. Initialize the array's elements to random integers between 1 and 10 (inclusive). c. Display all the elements in the 2D array as a table of rows and columns. d. Display the row index and column index of all the even integers in the 2D array. e. Display the sum of first row's elements.
Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...