本文最后更新于:4 个月前

问题描述

  在1至2019中,有多少个数的数位中包含数字9?
 注意,有的数中的数位中包含多个9,这个数只算一次。例如,1999这个数包含数字9,在计算只是算一个数。

答案提交

  这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

​ 答案:544

代码实现

/**
 * @Classname Main
 * @Description 模拟带九9的数的个数
 * @Date 2020/3/15 下午 2:21
 * @Created by jerry
 */
public class Main {
    public static void main(String[] args) {
        int count=0;
        A:	for (int i = 1; i <=2019; i++) {
            int a=i;
            while(a!=0){
                int b = a%10;
                if(b==9){
                    count++;
                    continue A;
                }
                a/=10;
            }
        }
        System.out.println(count);
    }

}

 目录