码迷,mamicode.com
首页 > 其他好文 > 详细

1021 各位数统计

时间:2019-07-01 01:14:13      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:color   oid   scanner   out   string   scan   形式   sys   class   

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]);
            }
        }
    }
}

 

1021 各位数统计

标签:color   oid   scanner   out   string   scan   形式   sys   class   

原文地址:https://www.cnblogs.com/Ymengchun/p/11111736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!