日期:2014-05-20 浏览次数:20677 次
public class Test{ public static void main(String args[]){ String string="3443"; System.out.println(sum("11122")); System.out.println(sum(string)); } public static String sum(String str){ StringBuffer string=new StringBuffer(); while(str.length()>0){ int length=str.length(); String s=str.substring(0,1); str=str.replaceAll("^"+s+"+", ""); string.append(s); string.append(length-str.length()); } return string.toString(); } }