public static void strZip(String s) { for (int i = 0; i < s.length(); i++) { int sum = 0; for (; (i + 1 < s.length()) && (s.charAt(i) == s.charAt(i + 1)); ) { i++; sum++; } System.out.print(s.charAt(i)); if (sum != 0) { System.out.print(++sum); } } }