Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3.Array Programming Program a static method named joiner that accepts two arrays of strings a1 and a2 as parameters and returns a new array a3

3.Array Programming

Program a static method namedjoinerthat accepts two arrays of stringsa1anda2as parameters and returns a new arraya3such that each element ofa3at each indexistoresa newstringcomposed of the words stored ata1[i]anda2[i]joined together with the word with thework havinggreater length (more characters)at the front of the concatenated string.If there is a tie, take the element froma1.

For example, ifa1anda2store the following elements:

String[] a1 = {"star","pie","jelly bean", "car"};

String[] a2 = {"cookie", "fig", "banana","soda"};

Then your method should returnthe new array:

{"cookiestar","piefig","jelly beanbanana","sodacar"}.

If the arraysa1anda2are not the same length, the result returned by your method should have as many elements as theshorter of the two arrays.For example, ifa1and a2 store the following elements:

String[] a1 = {"Splinter", "Leo","April", "Don", "Raph"};

String[] a2 = {"Krang","Shredder", "Bebop"};

Then your method should returnthe new array:

{"SplinterKrang","ShredderLeo","AprilBebop"}.

For full credit, do not modify the elements ofa1ora2.Do not make any assumptions about the length ofa1ora2or the length of the strings.You may assume that neither array isnullandthatno element of either array isnull.

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 Programming questions