public class TestComNum {
/**
* @param args
*/
public static void main(String[] args) {
for (int i = 2; i<= 1000; i++)
if (printComNum(i))
{
System.out.println(i);
}
}
static boolean printComNum(int i){
int sum = 0;
int j;
for (j = 1; j <= i / 2; j++)
{
if (i % j == 0)
{
sum += j;
}
}
return i == sum;
}
}
JAVA 4-1 求完数
最新推荐文章于 2022-03-10 06:00:00 发布