Java Program to check a number is strong number or not


In this program, You will learn how to check a number is strong number or not in Java.


Some list of strong numbers is : 1, 2, 145


Example: How to check a number is strong number or not in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int n, t, f, r, i, s = 0;

        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a Number :");
        n = sc.nextInt();
        t = n;

        while (n > 0) {
            r = n % 10;
            f = 1;
            for (i = 1; i <= r; i++) {
                f = f * i;
            }
            s = s + f;
            n = n / 10;
        }

        if (s == t){
            System.out.println("\nIt is a Strong Number :" + t);
        }else{
          System.out.println("\nIt is Not a Strong Number :" + t);
        }

    }
}

Output:

Enter a Number :145
It is a Strong Number :145