public class FindPerfectNumber
{
public static void main(String[] args)
{
//100
for(int i=2; i<100; i++)
{
int sum=0;
//查找因数
兆卖握 for(int j=1; j {
if(i % j==0)
族庆 {
sum += j;
}
if(sum==i)
配启 System.out.println(i);
}
}
}
}
请采纳,,
public static void completeNumber(int number){
Listlist = new ArrayList ();
list.add(1);
for (int i = 1; i <= number /2; i++) {
for (int j 郑颂= 1; j < i; j++) {
if ( i * j == number) {
list.add(i);
list.add(j);
}
}
}
int count = 0;
for (int i = 0; i < list.size(); i++) 悉链{
count 睁丛孙+= list.get(i);
}
if (count == number) {
System.out.println(number);
}
}
public static void main(String[] args) {
for (int i = 2; i < 100; i++) {
completeNumber(i);
}
}
用这个方法运行下就可以了
结果:
6
28