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

 

andersoniii.edwin@cusd80.com > Collapse2
prev  |  next  |  chance

Write a method called Collapse2 that accepts an array of integers as a parameter and returns a new array containing the result of replacing each pair of integers with the sum of that pair. For example, if an array called nums contains the values {7, 2, 8, 9, 4, 13, 7, 1, 9, 10}, then the call to the method Collapse2 should return a new array containing {9, 17, 17, 8, 19}. The first pair from the original list 7 + 2 = 9 and so on. If the given array of numbers has an odd number of elements then place the last element into the new array.


Collapse2([7, 2, 8, 9, 4, 13, 7, 1, 9, 10]) → [9, 17, 17, 8, 19]
Collapse2([]) → []
Collapse2([2, 2]) → [4]

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

public int[] Collapse2(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: 110

Copyright Nick Parlante 2017 - privacy