Number.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
public class Number {
public void sum(){
int i=0,j=0,r=0;
int num=1000;
for(i=1;i<num;i++){
r=0;
for(j=1;j<i;j++){ //找到所有因子并把他们相加
if(i%j==0){
r=r+j;
}
}
if(r==i){ //判断是否是完数
System.out.println(r);
}
}
}
}
Test.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
public class Test {
public static void main(String[] args){
Number n=new Number();
n.sum();
}
}