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
We initialize the parameters to all zero values and run the linear perceptron algorithm through these points in a particular ord
Usimov [2.4K]

The main aim of running the parameters in the linear perceptron algorithm is to be able to develop a machine learning algorithm for binary classification tasks.

<h3>What is a linear perceptron algorithm?</h3>

This refers to the linear classification algorithm that is used in machine learning.

This is done in order to learn a decision boundary that divides different classes using a hyperplane.

Hence, we can see that your question is incomplete because the parameters are not included, hence a general overview was given to give you a better understanding of the concept.

Read more about machine learning here:

brainly.com/question/25523571

#SPJ1

7 0
2 years ago
What is the biggest type of gear?<br><br>A. Spur<br>B.Worm<br>C.Wheel<br>D.Pinion
AnnZ [28]
The answer to this should be B. Worm. A pinion is a the smallest gear out of the listed ones above. spur would be next then wheel and the biggest if them all would be the spur. I'm not completely sure if my answer is 100% correct, but I feel confident enough about it. Hope this helps. :)

7 0
2 years ago
Read 2 more answers
The various online technology tools that enable people to communicate easily via the Internet to share information and resources
seropon [69]

Answer:

Social media is the correct answer for the above question.

Explanation:

  • Social media is the media that is used to communicate with the other person with the help of an internet connection. There is so much software that gives this type of facility. for example whats up and twitter.
  • The above question asked about that technology which is used to connect the people to communicate and the technology is social media which gives the features to connect and communicate all over the world with the help of the internet. Hence "Social media" is the correct answer.
8 0
2 years ago
What is percent encoding and why is it used?
ehidna [41]

Answer:

 Percent encoding is the mechanism for encoding the information in the URI  (Uniform resource identifier) that basically transmitted the special variable or characters in the URI to the cloud platform.

It is also used in various application for transferring the data by using the HTTP requests.

Percent encoding is also known as uniform resource locator (URL) encoding. The percent encoding basically used to convert the non ASCII characters into URL format which is basically understandable to the all the web server and browsers. In percent encoding the percent sign is known as escape character.

7 0
2 years ago
IVD. IIIcelTICISTUSTUSE LIICIULUI 1.12. Which of the two systems do you think will need the largest motor? Explain your answer.​
zhannawk [14.2K]
Transmission motor motor
8 0
3 years ago
Other questions:
  • When using a wireless mouse, what is the most common port used for the transmitter? 
    7·1 answer
  • Customers access the internet through what usually for a monthly fee
    14·1 answer
  • In several languages, the visual development environment is known by the acronym ____.
    12·1 answer
  • Life can get busy and hectic but relationships matter what is an effective way to mending relationships that may have been negle
    9·1 answer
  • Courteous behavior on the road will
    10·2 answers
  • What does f.i.r.s.t stand for in robotics
    15·1 answer
  • Which is NOT an example of a "Serious Game"?
    9·1 answer
  • Why is it difficult to convince top management to commit funds to develop and implement a Strategic Information System
    13·1 answer
  • What is modern? explain​
    11·1 answer
  • 1. What are the advantages and disadvantages of technology in communication?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!