Question: Run-length encoding (RLE) is a simple "compression algorithm" (an algorithm which takes a block of data and reduces its size, producing a block that contains the same information in less space). It works by replacing repetitive sequences of identical data items with short "tokens" that represent entire sequences. Applying RLE to a string involves finding sequences in the string where the same character repeats. Each such sequence should be replaced by a "token" consisting of:
the number of characters in the sequence
the repeating character
If a character does not repeat, it should be left alone.
For example, consider the following string:
qwwwwwwwwweeeeerrtyyyyyqqqqwEErTTT
After applying the RLE algorithm, this string is converted into:
q9w5e2rt5y4qw2Er3T
This is what I have so far, I don't know how to count the characters like how many times a character is repeated. Can someone please help!!!!
public class Compress1 {
public static void main(String[] args){
System.out.println("Enter a string");
String input = IO.readString();
char[] inputChar = input.toCharArray();
for (int index = 0; index < inputChar.length; index++){
char current = inputChar[index];
if (current == (current + 1)){
int count =
}
}
}
}