Program to find Strong number in Java
What is strong number?
Strong number is a special number whose sum of the factorial of digits is equal to the original number. For Example: 145 is strong number. Since, 1! + 4! + 5!
Code
//Program to Check the given Number is STRONG Number or not.
// Logic 145 = 1! + 4! + 5! (i.e., 145 = 1 + 24 + 120 )class StrongTest
{
public static void main( String args[ ] )
{
int n, x, r, sum, f, i;
n = 145;
x = n;
sum = 0;
while( n != 0 )
{
r = n % 10;
f = 1;
for( i=1 ; i<=r ; i++ )
{
f = f * i;
}
sum = sum + f;
n = n / 10;
}
if( sum == x )
System.out.println( x + " is a STRONG Number." );
else
System.out.println( x + " is not a STRONG Number." );
}
}
Output:
145 is a STRONG Number.