Question: The following code segment is part of a bigger program to add the corresponding values of two arrays, a1 and a2. Arrays a1 and a2

The following code segment is part of a bigger program to add the corresponding values of two arrays, a1 and a2. Arrays a1 and a2 are declared and initialized to store five doubles.

double[ ] a1 = new double[5]; double[ ] a2 = new double[5]; // Assume that there is code here that prompts the user to enter these 10 double // values and stores them in a1 and a2. You don't know what the user will type, but // you may assume that the code is correct and no errors occur in this portion of the program. // Complete your code below this line

Add code to do the following:

  • declare an additional array of five doubles>
  • fill the new array with the sum of the corresponding elements in a1 and a2
  • print the values stored in the new array to the screen

For example, if the first two arrays hold the following values: {1.2, 2.3, 3.4, 4.5, 5.6} and {1.0, 2.0, 3.0, 4.0, 5.0},

your array should be filled with the following values: {2.2, 4.3, 6.4, 8.5, 10.6}

Complete the code segment to accomplish the additional tasks described.

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!