Perfect number – a number is called a Perfect number if it is equal to the sum of its factors other
than the number itself. Example: 6 = 1 + 2 + 3.
Program:
import java.util.*;
class Perfect_pure_fun
{
public int fun(int n)
{
int s=0,i;
for(i=0;i<n;i++)
{
if(i%2==0)
s=s+i;
}
return(s);
}
public static void main(String[] args)
{
int no,p;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number: ");
no=sc.nextInt();
Perfect_pure_fun obj=new Perfect_pure_fun();
p=obj.fun(no);
if(p==no)
{
System.out.println("Entered number is perfect");
}
else
System.out.println("Entered number is not perfect");
}
}
Output:
Enter the number:
6
Entered number is perfect.
Enter the number:
6
Entered number is not perfect.