Java Program to check a number is a strong number or not


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


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

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

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("It is a strong number:" + t);
        }else{
            System.out.println("It is not a strong number:" + t);
        }

    }
}

Output:

Enter a number:145
It is a strong number:145