Perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3. Other perfect numbers are 28, 496, and 8,128.
Code::
import java.util.*;
public class PerfectNumber
{
public static void main(String[] nt)
{
Scanner in= new Scanner(System.in);
System.out.print("Enter any Number: ");
int n=in.nextInt();
int temp=n;
int sum=0;
for(int i=1;i<n;i++)
{
if(temp%i==0)
{
sum=sum+i;
}
}
if(sum==n)
{
System.out.println("Yes it is a Perfect Number");
}
else
{
System.out.println("No it is not a Perfect Number");
}
}
}
Code::
import java.util.*;
public class PerfectNumber
{
public static void main(String[] nt)
{
Scanner in= new Scanner(System.in);
System.out.print("Enter any Number: ");
int n=in.nextInt();
int temp=n;
int sum=0;
for(int i=1;i<n;i++)
{
if(temp%i==0)
{
sum=sum+i;
}
}
if(sum==n)
{
System.out.println("Yes it is a Perfect Number");
}
else
{
System.out.println("No it is not a Perfect Number");
}
}
}
Output::