Strong Number in Java
What is a Strong Number?
A Strong number is a number whose sum of all digits factorial is equal to the number. For instance,145 is a Strong Number as 1! + 4! + 5! is equal to 145 only.
Compile and Run the following code with Command-Prompt Or download Notepad++
For Compilation javac Sample.java
For Execution java Sample
import java.util.Scanner; class Sample { public static void main(String args[]) { int n,i,p,r,sum = 0,num; Scanner sc = new Scanner(System.in); System.out.println("Enter the number of your choice: "); n = sc.nextInt(); num = n; while(num ! =0) { i = 1; p = 1; r = num % 10; while(i<=r) { p = p*i; i++; } } if(sum == num) System.out.println("This is a Strong Number"); else System.out.println("This is not a Strong Number"); } }