Menu
Topics Index
...
`

Is A Strong Number Or Not - Java Example Program


Is A Strong Number Or Not
class IsAStrongNumberOrNot
{
    public static void main(String s[])
    {
        int input = 145;
        
        int temp, mod, sum = 0;
    
        temp = input;
    
        while(input > 0)
        {
            mod = input % 10;
    
            sum=sum + fact (mod);
    
            input  = input /10;
                    
        }
        if(temp == sum)
        {
            System.out.println(temp +" is a strong number");
        }
        else
        {
            System.out.println(temp +" is not a strong number");
        }
    }
    public static int fact(int num)
    {
        int fact=1;
    
        for(int i = 1; i <= num; i++)
        {
            fact *= i;
        }
        return fact;
    }
        
}
OUTPUT

145 is a strong number

DESCRIPTION

THINGS TO TRY
  • Check whether 240 is a strong number or not. The output should be 240 is not a strong number.
  • Check whether 4058 is a strong number or not. The output should be 4058 is a strong number.

© meritcampus 2019

All Rights Reserved.

Open In App