[问题描述]
一个数如果除了 1 和自己还有其他约数,则称为一个合数。例如: 1,2,3不是合数,4.6 是合数
请问从 1 到 2020 一共有多少个合数。
public class Demo {
public static void main(String[] args) {
int num = 2020;
int count = 0;
for(int i = 1; i <= num;i++) {
for(int j = 1;j <= i;j++) {
int temp = 0;
//i的约数
if(i % j == 0) {
temp = j;
//约数判断
if (temp != 1 && temp != i) {
count++;
break;
}
}
}
}
System.out.println(count);
}
}