完数:一个数如果恰好等于除其本身的因子之和
例:28=1+2+4+7+14
- public class Test53 {
- public static void main(String[] args) {
- int sum, i, j;
- int count = 0;
- int[] a = new int[50];
- System.out.println("1000以内的完数有:");
- for(i = 2; i < 1000; i++){
- sum = 0;
- count = 0;
- for(j = 0; j < 20; j++){
- a[j] = 0;
- }
- for(j = 1; j <= i/2; j++) {
- if(i%j == 0){
- sum += j;
- a[count] = j;
- count++;
- }
- }
- if(sum == i){
- System.out.print(i + " = ");
- for(j = 0; j < count; j++){
- System.out.print(a[j] + " + ");
- }
- System.out.print("\b\b\b\n");
- }
- }
- }
- }
本文出自 “年少的风” 博客,请务必保留此出处http://huamm.blog.51cto.com/5646020/1037097