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]
3 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]3 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
______are our thoughts and feelings towards a particular subject
ddd [48]
c....attitudes.....
8 0
2 years ago
Describe how spacecraft evolved from the US Mercury to contemporary space shuttles.
pashok25 [27]

Answer:

Several of the subsystems evolved during the program through design changes: The parachute system, essential for booster recovery, was redesigned with larger parachutes in 1983. Frangible nuts, used in the space shuttle pad hold down and release system, were redesigned in 2008.

8 0
2 years ago
When you ask the database more complex questions using comparison operators, you are conducting a _____. sort questionnaire quer
Mice21 [21]
The correct answer is known as a "query".

When you ask a lot of complex questions , which uses comparison operators, that is called a query. A query refers to the <span>exact request for </span>data retrieval<span> with the use of database and information systems. </span>
8 0
3 years ago
Which are elements involved in diagramming a solution? Choose all that apply.
katovenus [111]

Answer:

1) showing a visual graphic of the solution

3) showing the flow of information through the solution

4) showing decision points

5) showing the path of information to decision points

Explanation:

 I'm sure this is the answer!!

4 0
3 years ago
So I try to login into my origin account and this popped up.(photo). But everytime I try to type in something I’m unable to clic
Oduvanchick [21]
You have to restart your computer or maybe use another internet browser to access the website your trying to reach
7 0
3 years ago
Other questions:
  • Which of the following would likely be covered under homeowners insurance but NOT by renter's insurance?
    9·2 answers
  • True or false over the course of ecological succession,species diversity increases over time?
    12·2 answers
  • As the performance of PCs steadily improves, computers that in the past were classified as midrange computers are now marketed a
    9·1 answer
  • Which security control is most helpful in protecting against eavesdropping on wireless LAN (WLAN) data transmissions that would
    6·1 answer
  • What is the name of the unique identifier assigned to any personal computer that is connected to the internet?
    11·1 answer
  • GIVING BRAINLIEST Jenna creates advertisements for companies to air on television. Which file format will best preserve the grap
    5·2 answers
  • MacBook Pro (2019) at 93% max capacity battery rating after 100 charge cycles. Is this normal? Used coconut battery to check thi
    10·2 answers
  • Can someone help me so I don’t fail this class:(
    14·1 answer
  • Use the drop-down menus to complete the statements about Search Folders.
    12·1 answer
  • Several small stores rent space within a larger shopping centre. The owners of the shopping centre have provided a physical netw
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!