You are here: Home / Topics / Program to find Strong number in Java

Program to find Strong number in Java

Filed under: Java on 2023-08-18 06:59:13

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.

About Author:
Y
Yatendra Sir     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.