Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Trees

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,978 questions

12,389 answers

573 users

How to check if a number is strong number or not in Java

1 Answer

0 votes
package javaapplication1;

// Strong numbers are the numbers that the sum of factorial of its digits 
// is equal to the original number
 
// 145 is a strong number: 1 + 24 + 120 = 145

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        int n = 145, reminder, sum = 0, tmp;
 
        tmp = n;
 
        while (n != 0)
        {
            reminder = n % 10;
            sum = sum + factorial(reminder);
            n /= 10;
        }
        if (sum == tmp)
            System.out.format("%d is a strong number\n", tmp);
        else
            System.out.format("%d is not a strong number\n", tmp);
    }
    public static int factorial(int n)
    {
        int fact = 1;
 
        for (int i = 2; i <= n; i++)
             fact = fact * i;
 
        return fact;
    }
}
   
/*
run:
  
145 is a strong number
   
*/

 




answered May 9, 2017 by avibootz
...