问题描述
一个数如果除了 1 和自己还有其他约数,则称为一个合数。例如:1, 2, 3 不是合数,4, 6 是合数。 请问从 1 到 2020 一共有多少个合数。
答案提交
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一 个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
代码分析
从2开始
代码展示
public class text2 {
public static void main(String[] args) {
int count=0;
for(int i =1;i<=2020;i++) {
for(int j =2;j<i;j++) {
if(i%j==0) {
count++;
break;
}
}
}
System.out.println(count);
}
}