check the number is perfect (using java)

 //if the addition of factors of a number except that number is same as original number then the number is perfect

ex n0=6  factor 1,2,3  that means 1+2+3=6  then it is perfect number

class perfect

{

public static void main(String args[])

{

int no=10,sum=0;

for(int i=1; i<no ; i++)

{

if(no%i==0)  // i is the factor of that number

{

sum=sum+i

}

}

if(sum==no)

System.out.println("perfect number");

else

System.out.println("not");

}}



Comments

Popular posts from this blog