id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-arrays > apcsaArraysPairMax
prev  |  next  |  chance

Heads up, this is a harder problem. Congratulations on making it here!


Given an array of ints, find the maximum of each pair of elements and duplicate it.  Thus, if the input array was {0, 4, 32, 10} the elements with index 0 and 1 in the output would both have the value 4, which is the greater of the input's first two elements.  The elements in the output at indexes 2 and 3 would have the value 32, since that is the greater of 32 and 10.  Precondition: a.length % 2 == 0, meaning that a will always have an even number of elements.

HINT: Math.max(int first, int second) will compute the larger of two numbers.

apcsaArraysPairMax([0, 4, 32, 10]) → [4, 4, 32, 32]
apcsaArraysPairMax([0, 0]) → [0, 0]
apcsaArraysPairMax([-5, 5, 14, 18, -20, 35]) → [5, 5, 18, 18, 35, 35]

...Save, Compile, Run (ctrl-enter)

public int[] apcsaArraysPairMax(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 250

Copyright Nick Parlante 2017 - privacy