Question: Write a method called collapse that accepts an array of integers as a parameter and returns a new array containing the result of replacing each
Write a method called collapse 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 list stores the values [7,2,8,9], then the call of collapse(list) should return a new array containing [9,17]. The first from the original list is collapses into 9 (7+2), the second pair is collapsed into 17 (8+9). If the list stores an odd number of elements, the final element is not collapsed

5. [17 points] Write a method called collapse 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 list stores the values [7,2,8,9], then the call of collapse(list) should return a new array containing [9,17]. The first from the original list is collapses into 9(7+2), the second pair is collapsed into 17(8+9). If the list stores an odd number of elements, the final element is not collapsed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
