完数

/*
题目:一个数如果恰好等于它的因子之和,这个数就称为 "完数 "。例如6=1+2+3.编程     找出1000以内的所有完数。  
*/
public class Test{
    //判断某个数是不是完数
    public static boolean isWanShu(int i){
    int t = 0;
      for(int j=1; j<= i/2; j++) {
       if(i % j == 0) 
        t = t + j;
      }
      return t==i;
    }
public static void main(String[] args) {
     System.out.println("1到1000的完数有: ");
     for(int i=1; i<1000; i++) {
       if(isWanShu(i))
            System.out.print(i+"\t");
     }
}
}
原文地址:https://www.cnblogs.com/laoquans/p/2963356.html