1到100之间0 1 2 3。。。9分别总共出现多少次 请发给我算法多谢了

来源:百度知道 编辑:UC知道 时间:2024/05/29 23:08:46

class Count{
public static void main(String args[]){
String s = "";
for(int i = 1;i <= 100;i++){
s=s+i;
}
int count0=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='0'){
count0++;
}
}
System.out.println("0出现了:"+count0+"次");
}
}

把0出现次数的程序给你吧,其他的一样

0出现10次有10、20、30、40、50、60、70、80、90、100
1出现11次有1、11、21、31、41、51、61、71、81、91
2出现11次有2、12、22、32、42、52、62、72、82、92
3出现11次有3、13、23、33、43、53、63、73、83、93
4出现11次有4、14、24、34、44、54、64、74、84、94
5出现11次有5、15、25、35、45、55、65、75、85、95
6出现11次有6、16、26、36、46、56、66、76、86、96
7出现11次有7、17、27、37、47、57、67、77、87、97
8出现11次有8、18、28、38、48、58、68、78、88、98
9出现11次有9、19、29、39、49、59、69、79、89、99