【年少的风】求1000以内的‘完数’

完数:一个数如果恰好等于除其本身的因子之和

例:28=1+2+4+7+14

 
 
  1.  
  2. public class Test53 {  
  3.  
  4.     public static void main(String[] args) {  
  5.         int sum, i, j;  
  6.         int count = 0;  
  7.         int[] a = new int[50];  
  8.           
  9.         System.out.println("1000以内的完数有:");  
  10.           
  11.         for(i = 2; i < 1000; i++){  
  12.             sum = 0;  
  13.             count = 0;  
  14.             for(j = 0; j < 20; j++){  
  15.                 a[j] = 0;  
  16.             }  
  17.             for(j = 1; j <= i/2; j++) {  
  18.                 if(i%j == 0){  
  19.                     sum += j;  
  20.                     a[count] = j;  
  21.                     count++;  
  22.                 }  
  23.             }  
  24.             if(sum == i){  
  25.                 System.out.print(i + " = ");  
  26.                 for(j = 0; j < count; j++){  
  27.                     System.out.print(a[j] + " + ");  
  28.                 }  
  29.                 System.out.print("\b\b\b\n");  
  30.             }  
  31.         }  
  32.     }  
  33.  
  34. }  

 

本文出自 “年少的风” 博客,请务必保留此出处http://huamm.blog.51cto.com/5646020/1037097

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值