Java实现第十届蓝桥杯求和

试题 A: 求和
本题总分:5 分
【问题描述】
小明对数位中含有 2、0、1、9 的数字很感兴趣,在 1 到 40 中这样的数包 括 1、2、9、10 至 32、39 和 40,共 28 个,他们的和是 574。 请问,在 1 到 2019 中,所有这样的数的和是多少?
【答案提交】
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一 个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分

//这道题没什么好说的for循环暴力破解
 

public class qiuhe {        //1905111
    public static void main(String[] args) {
        int count=0,temp=0;
        for (int i = 1; i <=2019; i++) {
            int b = i;
            temp=i;
            while(b!=0){
                int a = b%10;
                if(a==2 || a==0||a==1||a==9){
                   count+=temp;
                    break;
                }
                b/=10;
            }
        }
        System.out.println(count);
    }
}




原文地址:https://www.cnblogs.com/a1439775520/p/12947764.html