Sunday, June 21, 2020

Write a program to input a number and check whether it is Abundant Number or not? (18= 1+2+3+6+9=21, sum>number)

31)  Write a program to input a number and check whether it is Abundant Number or not? (18= 1+2+3+6+9=21, sum>number)

import java.util.*;
public class Abundant_number
{
     public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int s = 0;
        for(int i=1;i<a;i++)
        {
            if(a%i==0)
            s=s+i;
        }
        if(s>a)
        {
            System.out.println("Entered number is a ABUNDANT number");
        }
        else
        {
            System.out.println("Entered number is not a ABUNDANT number");
        }
    }
}

No comments:

Post a Comment

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj