Compress string such as 'AAABBCCCCCCAAAAA' to '3A2B6C5A'
Sigiloso
public class Compressor { public static void main(String[] args){ String orig = args[0]; if (args[0] == null) return; char current = orig.charAt(0); int count = 1; String result = new String(); for (int i=1; i < orig.length(); i++){ System.out.println(i +"\t" + current +"\t" + count); if (orig.charAt(i)== current){ count ++; } else { result += Integer.toString(count) + current; current = orig.charAt(i); count = 1; } } result += Integer.toString(count) + current; System.out.println(result); } }