{
public static void main(String[] args)
{
int sum
int i=2
while(i!=1001)
{
sum = 0 //每次循环sum重新赋值为0
for(int j=1j<ij++)
{
if (i%j==0) sum+=j
}
if(i==sum) System.out.println(i+" ")
i++
}
}
}
public class PerfectNum
{
public static void main ( String[] args )
{
for ( int i = 2 i < 1000 i++ )
{
if (perfectNum (1, i) == i)
{
System.out.print (i + " ")
}
}
}
private static long perfectNum ( long start, long num )
{
if (start > num / 2)
{
return 1
}
start++
if (num % start == 0)
{
return start + perfectNum (start, num)
}
else
{
return perfectNum (start, num)
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)