Write a program to check whether the
inputted number is Perfect Number or
not, print Perfect if it is a Perfect
Number otherwise print Not Perfect.
A PERFECT number is a positive
integer that is equal to the sum of its
positive divisors, excluding the number
itself.
For example, 6 can be divided by 1, 2
and 3, and also the sum of 1 + 2 + 3 =
6, so 6 is a perfect number.
Answers
Answered by
2
Answer:
import java. util. *;
class number
{
public static void main (string args [] )
{
scanner sc = new scanner ( system. in) ;
system. out. print ( "Enter a number :- ") ;
int a = sc.next () ;
int i, s=0;
for( i = 1 ; i <= a ; i++ )
{
if (a%i=0)
{
s=s+1;
}
}
if (s==a)
{
system.out.println(" It is a perfect number ") ;
}
else
{
system.out.println(" It is not a perfect number ") ;
}
}
}
Similar questions