Introduction to Object-Oriented Programming
I’m studying for my Engineering class and need an explanation.
Run length encoding is one way to compress a sequence with lots of repeated entries. In run length encoding, repeated entries in a sequence are replaced by a counter of how many times the entries are repeated. For example, the sequence 1 1 1 1 2 2 2 4 6 6 6 6 6 1 1 gets encoded in the following manner
1⏟1112⏟22 ⏟4 6⏟6666 1⏟1 ⟹14 23 41 65 124 times 3 times 1 time 5 times 2 times
into the sequence 1 4 2 3 4 1 6 5 1 2, where the encoded sequence consists of pairs in the form entry counts entry counts entry counts, and so on. Notice that the encoded sequence is shorter than the original sequence as long as there are many repeated entries.
Write a program that prompts the user to enter a sequence of integers, separated by a space between each integer, and display the run length encoded output. If the user enters an empty sequence, do not output anything. You may assume that the entered sequence is valid (i.e. in the correct format) and contains only integers.
Submit your source code in a file named RunLengthEncoding.java!
Sample input and output (inputs preceded by >):
Enter a sequence of integers separated by spaces: >111122246666611
Run length encoder output:
1423416512
Enter a sequence of integers separated by spaces: > 3 3 -5 -5 -5 -5 2 4 4 4 0
Run length encoder output:
3 2 -5 4 2 1 4 3 0 1
ORDER YOUR ORIGINAL PAPER
Request for a custom paper or place a new order
THE BEST CUSTOM ESSAY WRITING SERVICE AT YOUR FINGERTIPS
Forget All Your Assignment & Essay Related Worries By Simply Filling Order Form