Write a java program to input an integer and check whether it is a perfect, abundant or deficient number. If the sum of the factors excluding itself is equal to that number it is perfect, if greater than that number it is abundant and if less than that number it is deficient number.
Answers
Answered by
25
Answer:
class check
{
public static void main (String args [])
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
int sum=0;
int i;
for(i=1;i<n;i++)
{
if(n%i==0)
sum=sum+i;
}
if(sum==n)
System.out.println("Perfect Number");
else if (sum>n)
System.out.println("Abundant Number");
else if (sum<n)
System.out.println("Deficient Number");
}
}
Please Subscribe my to Youtube Channel Study To Study ICSE-Swapnil Mehta for more Java Programs
Explanation:
Hope it will help you
Please mark me as brainlist :)
Similar questions