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

 

condense


Write a method called condense 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, 4, 13, 7, 1, 9, 10}, then the call of condense(list) should return a new array containing {9, 17, 17, 8, 19}. The first pair from the original list is condensed into 9 (7 + 2), the second pair is condensed into 17 (8 + 9), and so on. If the list stores an odd number of elements, the final element is not condensed. For example, if the list had been {1, 2, 3, 4, 5}, then the call would return {3, 7, 5}. Your method should not change the array that is passed as a parameter.


condense([7, 2, 8, 9, 4, 13, 7, 1, 9, 10]) → [9, 17, 17, 8, 19]
condense([1, 2, 3, 4, 5]) → [3, 7, 5]
condense([0, 2, 8, -9, 4, 0, 7, 1, 1, 2]) → [2, -1, 4, 8, 3]

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

public int [] condense(int [] arr) }

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: 200

Copyright Nick Parlante 2017 - privacy