原字符串: 91254782354987012345978
输出 :0:1 1:2 2:3 3:2 4:3 5:3 7:3 8:3 9:3
参考代码如下
public class Hello {
public static void main(String[] args) {
String s = "912547823549870112345978";
int a[] = new int[10];
for (int i = 0; i < s.length(); i++) {
a[s.charAt(i) - '0']++;
}
for (int j = 0; j < 10; j++) {
System.out.printf(j + ":" + a[j] + " ");
}
}
}