Java实现蓝桥杯模拟带九9的数的个数

问题描述
  在1至2019中,有多少个数的数位中包含数字9?
  注意,有的数中的数位中包含多个9,这个数只算一次。例如,1999这个数包含数字9,在计算只是算一个数。
答案提交
  这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

package 第十三次模拟;

public class Demo4求带9的数 {
	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);
	}

}

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