public static void main(String[] args) {
// TODO Auto-generated method stub
int n=10000000,h=n/10,c=n%10,l=0,t=1;
int res=0;
while (h!=0||c!=0)
{
if (c==0) {res+=h*t;}
else if (c==1) {res+=h*t+1+l;}
else {res+=(h+1)*t;}
l+=c*t;
c=h%10;
h/=10;
t*=10;
}
System.out.println(res);
}
结果:
7000001
1~n整数中1出现的次数
最新推荐文章于 2022-11-08 17:49:04 发布