Strong Number Check in Java: Explanation & Practice

Check if a number is a strong number

Problem summary

A strong number equals the sum of factorials of its digits (e.g., 145 = 1! + 4! + 5!). Check if the given number is strong.

Starter code

public class Main {
    public static void main(String[] args) {
        int number = 145; // Test case 1
        
        // Check if strong number
        // Print: Is strong: <true/false>
    }
}

Expected output and test cases

  • 145 = 1!+4!+5! = 145
    Is strong: true
  • 2 = 2! = 2
    Is strong: true
  • 123 is not strong
    Is strong: false

Hints

  1. Extract each digit
  2. Calculate factorial of each digit
  3. Sum factorials and compare with original

Related Core Java Basics exercises

Practice all Core Java Basics exercises · Run this idea in the Java compiler