Question: show result in java please!! This lab was designed to reinforce programming concepts from this lab, you will practice: Declaring and initializing arrays. Comparing input

show result in java please!!show result in java please!! This lab was designed to reinforce programming

This lab was designed to reinforce programming concepts from this lab, you will practice: Declaring and initializing arrays. Comparing input to array elements. Preventing array out-of-bounds errors. The follow-up questions and activities will also give you practice: Initializing array sizes during program execution. Description. Write a static method named longer that accepts two arrays of strings al and a2 as parameters and returns a new array a3 such that each element of a3 at each index i stores whichever string has greater length (more characters) between the elements at that same index i in arrays al and a2. If there is a tie, take the element from al. For example, if al and a2 store the following elements: string[] al = { "star", "pie", "jelly bean", "car"}; string[] a2 = { "cookie", "fig", "banana", "soda"}; Then your method should return the new array {"cookie", "pie", "jelly bean", "soda"}. If the arrays al and a2 are not the same length, the result returned by your method should have as many elements as the larger of the two arrays. If a given index is in bounds of al but not a2 (or vice versa), there are not two elements to compare, so your result array's element at index i should store the value "oops". For example, if al and a2 store the following elements: String[] al = { "Splinter", "Leo", "April", "Don", "Raph"}; string[] a2 = { "Krang", "Shredder", "Bebop"}; Then your method should return the new array("Splinter", "Shredder", "April", "oops", "oops"}. Do not modify the elements of al or a2. Do not make any assumptions about the length of al or a2 or the length of the strings. You may assume that neither array is null and no element of either array is null

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!