Java: Write a static method called shorten that takes an ArrayList of Integers as

profileadelen
 (Not rated)
 (Not rated)
Chat

 

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
 

    • 7 years ago
    java file attached
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      Programming.java