找出1000以内的完数Java

题目

一个数如果恰好等于它的因子之和,这个数就称为 "完数 "。例如 6=1+2+3.编程 找出 1000 以内的所有完数。

public class perfectNumber{
    
    
	public static void main(String[] args) {
    
     
		System.out.println("1 到 1000 的完数有: "); 
		for(int i=1; i<1000; i++) {
    
    
			int t = 0;
			for(int j=1; j<= i/2; j++) {
    
    
				if(i % j == 0) {
    
    
					t = t + j;
				}
			}
			if(t == i) {
    
     
				System.out.print(i + "	");
			}
		}
	}
}

猜你喜欢

转载自blog.csdn.net/p715306030/article/details/113930082