Run-length encoding replaces repeated characters by one character and a count: aaabccdddd → a3bc2d4 (a count of 1 is not written).
Write RunLength with static String compress(String s) and static String expand(String s) (counts may have several digits: x12 means twelve x's), both using a StringBuilder. For each word of the input print
aaabccdddd -> a3bc2d4 (10 -> 7 chars) back: ok
reversed: ddddccbaaa
back checks that expand(compress(w)) equals w. Use new StringBuilder(word).reverse() for the second line.