Question: 1. Convert the following c++ codes into java: #include /* File: lab2.cpp */ #include // included for the random number generator functions srand() and rand()

1. Convert the following c++ codes into java:

#include  /* File: lab2.cpp */ #include  // included for the random number generator functions srand() and rand() #include  // included for passing the current time as seed of the random number generator #include  // included for sleep(1), this is NOT needed in the Java program! using namespace std; int maximum; //this is the upper bound of the random number generated in randArray, the biggest random number is maximum-1 //generate the random integers to fill out the array a[] void randArray(int a[], int n) {//n is the size of the array a[] srand (time(NULL)); for (int i=0;i<=n-1;i++) { a[i]=rand() % maximum; // rand() returns non negative integers } } //Find unique common numbers in a[] and b[], put them to c[], return the number of common elements copied to c[] at the end int findCommon(int a[],int aSize, int b[], int bSize, int c[], int cSize) {//n is the size of the array a[] for (int i=0;i>maximum; //fill the array a[] random non negative integers randArray(a, sizeof(a)/sizeof(*a)); //print out the arrays a[] before doing the check cout << " The original integer array a[] is: " << endl; printArray(a, sizeof(a)/sizeof(*a)); //sleep for 1 second, so that the random seed in randArray() will be different for a[] and b[] //*This line is NOT required in Java* sleep(1); //fill the array b[] random non negative integers randArray(b, sizeof(b)/sizeof(*b)); //print out the arrays b[] before doing the check cout << " The original integer array b[] is: " << endl; printArray(b, sizeof(b)/sizeof(*b)); //find the common elements and put them to c[] cSize=findCommon(a, sizeof(a)/sizeof(*a), b,sizeof(b)/sizeof(*b), c, 0);//current size of c is 0 // print array c[] cout << " Common elements in a[] and b[] are: " << endl; printArray(c,cSize); return 0; } 

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!