第1个回答 2013-03-13
public static void main(String[] args) {
//7个数字最多组成的是7位数,所以要小于10000000
int size = 10000000;
int count = 0;
//循环所有的数
for(int i = 0; i < size; i++) {
//偶数排除掉
if(i % 2 == 0) {
continue;
}
//将数字转换成字符串
String str = String.valueOf(i);
//在这个字符串中,包含8和9的都不是想要的
if(str.contains("8") || str.contains("9")) {
continue;
}
//如果该数字符合要求,就将计数器加1
count++;
//输出了符合要求的数,由于数量太大,你可以分段打印出来想要的结果
//System.out.print(i);
}
System.out.println(count);
}