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
Ray Of Light [21]
4 years ago
10

Exercise on Single Dimensional Arrays Declare an array reference variable arrayInt for an array of integers. Create the array of

size 100, and assign it to arrayInt. (2 points) Write a method to populate the array with Random numbers between 1 to 25. Signature of the method is: populateArray( int[] ) which returns nothing. Call this method from main with arrayInt--> populateArray(arrayInt). (2 points) Write a method to print an array. Signature of the method is: printArray( int[] ) which returns nothing. Print maximum of ten(10) numbers on a line (see sample output below). Call this method from main with arrayInt--> printArray(arrayInt). Hint: Use the modulus operator. Any number n % 10 will return a value 0-9. (3 points) Write a method that finds the average of the array elements. Signature of the method is: findAverage( int[] ) which returns the average to the calling program.Call this method from main with arrayInt--> findAverage(arrayInt). github
Computers and Technology
1 answer:
victus00 [196]4 years ago
4 0

Answer:

//Import the Random class to allow for the generation of random numbers

import java.util.Random;

public class SingleDimensionalArray {

public static void main(String[] args) {

 // Declaration of an array reference variable for an array of integers

 int[] arrayInt;

 // Creating an array of size 100 and assigning it to arrayInt

 arrayInt = new int[100];

 // Call the method to populate array

 populateArray(arrayInt);

 // Call the method to print array elements with a maximum of ten numbers on a

 // line

 printArray(arrayInt);

 // Call the method to find the average of the elements in the array

 System.out.println("\nThe average of the array elements is " + findAverage(arrayInt));

}

// Method to populate array with random numbers between 1 and 25

// Since it is not specified, 1 and 25 are not inclusive

public static void populateArray(int[] arr) {

 // Create an object of the Random class to generate the random numbers

 Random random = new Random();

 // Create a loop that cycles 100 times beginning at n=0

 // At every cycle, generate a random number and add it to the array

 for (int n = 0; n < arr.length; n++) {

  arr[n] = random.nextInt(23) + 2;

 }

}

// Method to print the elements in an array

public static void printArray(int[] arr) {

 // Create a loop that cycles through the array.

 // At each cycle, the element in the array corresponding to the pointer (n) of

 // the array is printed.

 // There are going to be 100 elements, maximum of 10 per line.

 // The if statement checks if 10 elements are already printed on a line.

 // If that's the case, a new line is printed for the next set of 10 elements.

 for (int n = 0; n < arr.length; n++) {

  if ((n > 0) && (n % 10 == 0)) {

   System.out.println();

  }

  System.out.print(arr[n] + " ");

 }

}

// Method to calculate the average of the elements in the given array

public static double findAverage(int[] arr) {

 // An integer variable to hold the sum of the elements is declared and

 // initialized to zero.

 int sum = 0;

 // A loop to cycle through the array while cumulatively summing the elements is

 // created.

 for (int n = 0; n < arr.length; n++) {

  sum += arr[n];

 }

 // The average of the elements is calculated using the result from the sum

 // above. The value is being type-cast to get a floating point value of the

 // average. This is the right thing to do as the average of numbers is more

 // likely to be a floating point number.

 // The result of the average is stored in a double variable called 'average'.

 double average = (double) sum / arr.length;

 // The average of the elements is returned from the method

 return average;

}

}

Explanation:

Please download the file attached to this response for a proper formatting of the code. The code contains comments explaining every segment of the code. Carefully go through the comments in the code.

Note: The function printArray() prints all the elements in the array - 10 elements per line. Since there is no sample format specified, I have assumed that the elements are separated just by spaces.

Hope this helps!

Download java
You might be interested in
Match each with the correct answer.
natta225 [31]

Answer:

1. E

2. C

3. F

4. D

5. A

6. B

Explanation:

CPU: this is known as the central processing unit and it is considered to be the brain of a computer system. It is the system unit where all of the processing and logical control of a computer system takes place.

A. Decode unit: decodes instructions and data and transmits the data to other areas in an understandable format.

B. Register unit: contains many separate, smaller storage units. Modern CPUs need only a few nanoseconds to execute an instruction when all operands are in its registers.

C. Bus unit: it is used to connect all the other major components together, accepts data, and sends data through the input and output bus sections.

D. Control unit: control of the overall operations of the CPU. The component of the central processing unit (CPU) that controls the overall operation of a computer is the control unit. It comprises of circuitry that makes use of electrical signals to direct the operations of all parts of the computer system. Also, it instructs the input and output device (I/O devices) and the arithmetic logic unit how to respond to informations sent to the processor.

E. Arithmetic logic unit (ALU): performs mathematical functions on data stored in the register area.

F. Cache: small temporary memory area that separates and stores income data and instructions.

8 0
3 years ago
Which model allows you to make subsystems in parallel?
boyakko [2]
The model is Parallel Distributed Processing Model (PDP) wherein m<span>Memory results from weblike connections among interacting processing units operating simultaneously, rather than sequentially ( also known as the connectionist model).</span>
8 0
3 years ago
UPS or FedEx plays what role in the supply?
nikdorinn [45]

Explanation:

the answer in the image above

8 0
2 years ago
Which of the following best explains how the Internet is a fault-tolerant system?
IrinaK [193]

Answer:

A

Explanation:

The Internet is fault-tolerant because cybercriminals can conceal their actions, allowing them the ability to carry out faulty actions without leaving a trace.

This statement is actually the same question I had to answer when in my 2nd year 1st semester in itt.
<3 enjoy

8 0
2 years ago
Read 2 more answers
Watson Studio is the IBM premier integrated development environment for data science and artificial intelligence practitioners.
fomenos

Answer:

c. Using the Data Refinery tool

Explanation:

Data wrangling and tidying in Data Science is the process whereby data to be analysed is obtained, cleaned and arranged before it is analysed in the environment.

Since Watson Studio happens to be an IBM premier integrated development environment for data science and artificial intelligence practitioners, there is need for them to have data softwares to make data scientists practitioners' works easier.

<em>In this scenario, the best tools to aid in tidying data in the Watson studio would be the use of </em><u><em>Data Refinery Tool.</em></u>

3 0
3 years ago
Other questions:
  • Using Python
    14·1 answer
  • You use_____ to view an XPS file
    10·1 answer
  • Write a program that produces a Caesar cipher of a given message string. A Caesar cipher is formed by rotating each letter of a
    14·1 answer
  • True or false? when intel places a sticker on computers showing their chip is inside, they are demonstrating their visible value
    7·1 answer
  • What provides quality education for students
    14·1 answer
  • When cleaning a firearm, what end of the firearm should you generally clean from?
    11·2 answers
  • How do you ask brainy a question without it not liking the question and saying it hurts their feelings?
    14·1 answer
  • A professor is working with five teams in his marketing research class. He decides to experiment with path-goal theory in helpin
    11·1 answer
  • Jonathan works with a team of graphic designers. They have a collection of images and have divided the image editing work among
    5·2 answers
  • Which sentence in the passage shows an effective way to protect your document from misuse? Claire has saved her research paper o
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!