Perfect Number:
A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum).
Program:
import java.io.*;class Perfect
{
public static void main(String args[]) throws IOException
{
System.out.println("Enter number");
DataInputStream din=new DataInputStream(System.in);
int number=Integer.parseInt(din.readLine());
int temp=0;
for(int i=1;i<number;i++)
{
if(number%i==0)
{
temp=temp+i;
}
}
if(temp==number)
{
System.out.println(number+" is a Perfect Number");
}
else
{
System.out.println(number+" is not a Perfect Number");
}
}
}
0 comments:
Post a Comment