日期:2014-05-19 浏览次数:20746 次
String s = "123456789695478"; char[] c = s.toCharArray(); StringBuilder sb = new StringBuilder(); for (int i=0; i<c.length; i++) { if ((i+1)%4 == 3 && i+1<c.length) { sb.append(c[i+1]).append(c[i]).append(" "); } else if ((i+1)%4 != 0) { sb.append(c[i]); } } System.out.println(sb);