Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that has a method called sumArrays and a method called printArray The method sumArrays takes in two arrays of doubles (arrayA, arrayB).

image text in transcribed
Write a program that has a method called sumArrays and a method called printArray The method sumArrays takes in two arrays of doubles (arrayA, arrayB). The method then creates a new Array that has the length of the longest array that is passed in. Then add the elements of arrayA and array in the same position and put the result in the new array (e.g., newArr[0]=array A[0]+arrayB[O]). If arrayA and arrayB are different lenghts, simply copy the extra elements of the longer array into the new array. Return the new array. The method header is: public static doublel sumArrays (double // arrayA, double arrayB) The method printArray takes in an array of doubles. It will print out the elements of the array on one line. The method header public static void printArray (double / arr] You will test your method in the main method of your program by using a Scanner: Read in an int(N) representing the length of arrayA. Then read in N values into arrayA. Read in another int(N) that represents the length of arrayB. Then read in N values into arrayB. Print arrayA and arrayB by calling printArray for each one Call the method sumArrays (passing in arrayA and arrayB). Print the returned array using printArray, Examples (note in example 1: 4 is the size of arrayA and 3 is the size of arrayB] Sample Input Sample output 42.55.3 10 2.73 2.5 67 8.1 2.55.3 1.0 2.7 2.5 6.7 8.1 5.0 12.0 9.1 2.7 3 4.7 10 21.2 4 34.5 44.22.0 5.0 4.7 10.0 21.2 34.5 44.22.0 5.0 39.254.2 23.2 5.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

D How will your group react to this revelation?

Answered: 1 week ago