1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ronch [10]
2 years ago
6

Exercise#3: Write a ch program that performs the following: Declare a two arrays called arrayA and arrayB that holds integer and

the size of each array is given by the user. b. The main method calls a method called fillArray(...) of type void to fill an array with a set of generated random integers between low and high (both inclusive). This method should be called twice to fill arrayA and then arrayB. (the values of High and low are read in the main method. ​
Computers and Technology
1 answer:
Serga [27]2 years ago
6 0

Answer:

The code for this problem is completed here. Comments are added, go and learn how things work.

Explanation:

// Arrays.java

import java.util.Random;

import java.util.Scanner;

public class Arrays {

     // method to fill an array with random numbers between low and high

     static void fillArray(int array[], int low, int high) {

           Random random = new Random();

           for (int i = 0; i < array.length; i++) {

                 // generating a value between low and high inclusive, adding to

                 // array

                 array[i] = random.nextInt(high - low + 1) + low;

           }

     }

     // method to print elements in an array

     static void printArray(int array[]) {

           for (int i = 0; i < array.length; i++) {

                 // displaying elements separated by tab space

                 System.out.print(array[i] + "\t");

                 // printing a line break after every 5th element, or if this is the

                 // last element.

                 if ((i + 1) % 5 == 0 || i == array.length - 1) {

                       System.out.println();

                 }

           }

     }

     // method to count the number of elements in array greater than value

     static int count(int array[], int value) {

           // initializing count to 0

           int c = 0;

           for (int i = 0; i < array.length; i++) {

                 if (array[i] > value) {

                       // incrementing c

                       c++;

                 }

           }

           return c;

     }

     // returns true if two arrays are same, else false

     static boolean isSame(int array1[], int array2[]) {

           if (array1.length != array2.length) {

                 // lengths mismatch

                 return false;

           }

           // checking if elements are same in same order

           for (int i = 0; i < array1.length; i++) {

                 if (array1[i] != array2[i]) {

                       // mismatch found

                       return false;

                 }

           }

           // same

           return true;

     }

     // returns the average of elements in an array

     static double findAverage(int array[]) {

           double sum = 0;

           // summing values

           for (int i = 0; i < array.length; i++) {

                 sum += array[i];

           }

           // finding average

           double avg = (double) sum / array.length;

           return avg;

     }

     // method to count the number of values greater than average of an array

     static int aboveAverage(int array[]) {

           // finding average of passed array using findAverage method

           double avg = findAverage(array);

           // finding number of elements in array>avg using count method

           int c = count(array, (int) avg);

           return c;

     }

     public static void main(String[] args) {

           // setting up a Scanner

           Scanner scanner = new Scanner(System.in);

           // prompting and reading size of arrayA

           System.out.print("Enter size of arrayA: ");

           int n1 = scanner.nextInt();

           // initializing arrayA

           int arrayA[] = new int[n1];

           // doing the same for arrayB

           System.out.print("Enter size of arrayB: ");

           int n2 = scanner.nextInt();

           int arrayB[] = new int[n2];

           // asking and reading low and high values

           System.out.print("Enter low and high values for random numbers: ");

           int low = scanner.nextInt();

           int high = scanner.nextInt();

           // filling both arrays

           fillArray(arrayA, low, high);

           fillArray(arrayB, low, high);

           // printing both arrays

           System.out.println("arrayA:");

           printArray(arrayA);

           System.out.println("arrayB:");

           printArray(arrayB);

           // reading an integer

           System.out.print("Enter an integer value: ");

           int value = scanner.nextInt();

           // displaying the number of elements in each array greater than above

           // value

           System.out.println("The number of elements greater than " + value

                       + " in arrayA: " + count(arrayA, value));

           System.out.println("The number of elements greater than " + value

                       + " in arrayB: " + count(arrayB, value));

           System.out.println("Both arrays are same: " + isSame(arrayA, arrayB));

           // finding and displaying average of arrayA

           double avgA = findAverage(arrayA);

           System.out.println("Average of all values in arrayA: " + avgA);

           // finding and displaying number of elements in arrayB greater than the

           // average of arrayB

           System.out.println("The number of elements greater than "

                       + "the average of arrayB" + " in arrayB: "

                       + aboveAverage(arrayB));

     }

}

You might be interested in
Which is a common problem caused by the widespread use of computers?
Andru [333]
Hacking would be a widespread problem.
8 0
3 years ago
Finish and test the following two functions append and merge in the skeleton file:
avanturin [10]

Answer:

Explanation:

#include <iostream>

using namespace std;

int* append(int*,int,int*,int);

int* merge(int*,int,int*,int);

void print(int*,int);

int main()

{ int a[] = {11,33,55,77,99};

int b[] = {22,44,66,88};

print(a,5);

print(b,4);

int* c = append(a,5,b,4); // c points to the appended array=

print(c,9);

int* d = merge(a,5,b,4);

print(d,9);

}

void print(int* a, int n)

{ cout << "{" << a[0];

for (int i=1; i<n; i++)

cout << "," << a[i];

cout << "}\n";

}

int* append(int* a, int m, int* b, int n)

{

int * p= (int *)malloc(sizeof(int)*(m+n));

int i,index=0;

for(i=0;i<m;i++)

p[index++]=a[i];

for(i=0;i<n;i++)

p[index++]=b[i];

return p;

}

int* merge(int* a, int m, int* b, int n)

{

int i, j, k;

j = k = 0;

int *mergeRes = (int *)malloc(sizeof(int)*(m+n));

for (i = 0; i < m + n;) {

if (j < m && k < n) {

if (a[j] < b[k]) {

mergeRes[i] = a[j];

j++;

}

else {

mergeRes[i] = b[k];

k++;

}

i++;

}

// copying remaining elements from the b

else if (j == m) {

for (; i < m + n;) {

mergeRes[i] = b[k];

k++;

i++;

}

}

// copying remaining elements from the a

else {

for (; i < m + n;) {

mergeRes[i] = a[j];

j++;

i++;

}

}

}

return mergeRes;

}

4 0
3 years ago
An organization’s IRP prioritizes containment over eradication. An incident has been discovered where an attacker outside of the
emmasim [6.3K]

Answer:

The correct answer is (a) Remove the affected servers from the network.

Explanation:

Solution:

Now, since the organisation top priority is more of  containment over eradication, an outbreak code that is hostile as an can be suppressed effectively by removing the web server completely from the over all network facilities or infrastructure.

Also, if the affected servers are not removed, it might affect the integrity, confidentiality of sensitive materials or documents which will be exposed to the outside world by the attacker.

4 0
3 years ago
Multibeam sonar technology uses _____.
blsea [12.9K]
More than one sound source and listening device<span>
</span>
8 0
3 years ago
Read 2 more answers
A _____ is a specially formatted file that, once mounted, or connected to a virtual machine appear and operate pretty much ident
Sever21 [200]

A <u>Virtual hard disk</u> is a specially formatted file that, once mounted, or connected to a virtual machine appear and operate pretty much identically to a physical hard drive.

<h3>What is a virtual hard disk?</h3>

A virtual hard disk (VHD) is a disk picture file format for storing the entire ranges of a computer's hard drive.

The disk image, sometimes called a virtual machine (VM), duplicates an existing hard drive, including all data and structural elements.

<h3>Why would you count a virtual hard disk?</h3>

Typically, a VHD comes in handy to add additional storage to a Hyper-V virtual machine, and thanks to its capacity to support other OS installations, you can even use this storage virtualization technology to make a dual-boot system without modifying an existing partition.

To learn more about  virtual hard disk , refer

brainly.com/question/4733444

#SPJ4

4 0
1 year ago
Other questions:
  • The ____ contains methods that allow you to set physical properties such as height and width, as well as methods that allow you
    14·1 answer
  • When desktop publishing software can interact with another software program, the two are said to
    6·1 answer
  • Abram was asked to explain to one of his coworkers the XOR cipher. He showed his coworker an example of adding two bits, 1 and 1
    7·1 answer
  • Company XYZ has a new employee named John Anderson. His employee ID is XYZ1234. His email address will be <a href="/cdn-cgi/l/em
    10·1 answer
  • Create the Following Menu in a loop so the menu will continually show until the user chooses to exit.AddMultiplyExitAdd a value
    10·1 answer
  • 4. Together, what do the divisions of the DHSMV do? A. Make sure lines are long B. Use more money than other government organiza
    14·1 answer
  • You are contacted by a project organizer for a university computer science fair. The project organizer asks you to hold a forum
    10·1 answer
  • 2 ways to make your computer work faster ( please help asap )
    6·1 answer
  • I will give Brainliest and Extra points for correct answers!!!
    13·2 answers
  • The idea that an object can exist separate from the executing program that creates it is called
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!