Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having a hard time understanding how the integers in this program functions. Maxes Write a static method named maxes that takes two arrays

I am having a hard time understanding how the integers in this program functions.

image text in transcribedimage text in transcribed
Maxes Write a static method named maxes that takes two arrays of integers as parameters and returns a new array that contains the larger element at each index of the parameter arrays. If the two arrays are not the same length, the result array should be the same length as the longer array, and should include elements from the longer array at indexes that do not exist in the shorter array. For example, suppose the following arrays are declared: int arr1 = {1, 2, 3, 4, 5}; int arr2 = {3, 1, 3, 6, 3 } ; int arr3 = {-1, -1, -1, -1, -1, -1, -1}; int arr4 = {5, 5, 5, 5}; The following table shows the result of various calls to maxes : Method Call Array Returned maxes(arr1, arr2) [3, 2, 3, 6, 5] maxes(arrl, arr3) [1, 2, 3, 4, 5, -1, -1] maxes(arri, arr4) [5, 5, 5, 5, 5] maxes(arr2, arr3) [3, 1, 3, 6, 3, -1, -1] maxes(arr2, arr4) [5, 5, 5, 6, 3] maxes(arr3, arr4) [5, 5, 5, 5, -1, -1, -1) Your method must not modify either of the parameters. You may assume that both arrays are not null . You are limited to the methods on the cheat sheet in solving this problem.import java. util. *; public class Maxes { public static void main (String args) { int arr1 = {1, 2, 3, 4, 5 } ; int arr2 = {3, 1, 3, 6, 3 } ; int arr3 = {-1, -1, -1, -1, -1, -1, -1}; int arr4 = {5, 5, 5, 5} ; System . out . println (Arrays . toString (maxes (arr1, arr2) ) ) ; System. out. printin (Arrays . toString (maxes (arr1, arr3) ) ) ; System. out . println (Arrays . toString (maxes (arr1, arr4) ) ) ; System . out. println(Arrays . toString (maxes (arr2, arr3) ) ) ; System. out . println (Arrays . toString (maxes (arr2, arr4) ) ) ; System. out . println (Arrays. toString (maxes (arr3, arr4) ) ) ; / / TODO: Your Code Here -> Write a method / / called maxes for this

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions