Sunday, September 22, 2013

Filled Under: , , , , , , ,

Perfect Number Checker Using while loop

Share

Code Box
------------------

/*Program to check input number is 
perfect or not using while loop*/

class per_while
{
public static void main(String a[])
{
int i,j,k,sum,mul;
sum=0;
mul=1;
i=1;
k=Integer.parseInt(a[0]);

while(i<k)
{
if(k%i==0)
{
mul=mul*i;
sum=sum+i;
}
i++;
}

if(sum==mul && k==mul)
{
System.out.println("perfect");
}
else
{
System.out.println("Not perfect");
}
}
}


0 comments:

Post a Comment