0---2007的数字中有几个7

来源:百度知道 编辑:UC知道 时间:2024/05/24 12:19:45
如7,17,27,37......107,117......

601

是要代码吗 ?如下:
public class HowMany7 {
public static void main(String[] args) {
char ch = '7'; // 做匹配用
int count = 0; // 计数
for (int i = 1; i < 2008; i++) {
String str = i + "";
char[] c = str.toCharArray();// 转换成数组
for (int j = 0; j < c.length; j++) {
if (ch == c[j]) {// 比较
count++;
break; // 这里如果想计算的是一共有多少个7就不要 如果是想计算有多少个
//数里有7就需要
}
;
}
}
System.out.println(count);
}
}

楼上做的很好了我就不说什么了