Code:
import java.util.Scanner;
class perfect
{
public static void main(String args[])
{
int a,b,c,d,i,sum=0,dsum=0;
Scanner in=new Scanner(System.in);
System.out.print("Enter a number : ");
a=in.nextInt();
for(i=1;i<=a;i++)
{
if(a%i==0)
{
sum=sum+i;
}
}
dsum=2*a;
if(sum<dsum)
{
System.out.println("it is a deficient number");
}
else if(sum==dsum)
{
System.out.println("it is a perfect number");
}
else
{
System.out.println("it is a abundant number");
}
}
}
class perfect
{
public static void main(String args[])
{
int a,b,c,d,i,sum=0,dsum=0;
Scanner in=new Scanner(System.in);
System.out.print("Enter a number : ");
a=in.nextInt();
for(i=1;i<=a;i++)
{
if(a%i==0)
{
sum=sum+i;
}
}
dsum=2*a;
if(sum<dsum)
{
System.out.println("it is a deficient number");
}
else if(sum==dsum)
{
System.out.println("it is a perfect number");
}
else
{
System.out.println("it is a abundant number");
}
}
}
No comments:
Post a Comment