1021 各位数统计

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();        //以字符串形式读取给定的数字
        
        int[] count = {0,0,0,0,0,0,0,0,0,0,0};    //count数组:存储0~9这十个数字出现的次数
        
        for(int i=0; i<str.length(); i++){
            count[str.charAt(i) - '0']++;
        }
         
        for(int i=0; i<10; i++){
            if (count[i] != 0) {
                System.out.println(i + ":" + count[i]);
            }
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/Ymengchun/p/11111736.html