import java.util.Scanner;
public class PerfectIntegers
{
public static void main(String args[])
{
int num,sum=0,count=2,p_count=0;
Scanner sc=new Scanner(System.in);
System.out.println("First four Perfect Integers are:");
while(true)
{
for(int i=1;i<=count/2;i++)
{
if(count%i==0)
sum+=i;
}
if(sum==count)
{
System.out.print(" " + count);
p_count++;
}
sum=0;
count++;
if(p_count==4)
break;
}
System.out.print("\nEnter a number: ");
num=sc.nextInt();
for(int i=1;i<=num/2;i++)
{
if(num%i==0)
{
sum+=i;
}
}
if(sum==num)
System.out.println(num + " is a perfect integer");
else
System.out.println(num + " is not a perfect integer");
}
}
Comments
Post a Comment