Question: Write a static method called shorten that takes an ArrayList of Integers as a parameter. It should replace each sequence of two or more equal

 Write a static method called shorten that takes an ArrayList of

Write a static method called shorten that takes an ArrayList of Integers as a parameter. It should replace each sequence of two or more equal Integers in the ArrayList with a single Integer equal to the sum of the Integers that were equal. For example, suppose that the parameter is an ArrayList named a containing: [3, 7, 7, 7, 3, 6, 6, 14] Then after calling shorten the ArrayList a should contain: [3, 21, 3, 12, 14] So the 3 occurrences of 7 were replaced with 21, and the 2 occurrences of 6 were replaced with 12. The two occurrences of 3 aren't changed, since they aren't next to each other

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!