Write a Java program to check whether a number is Special or not.

A number is said to be Special if the sum of the factorial of its digits is equal to the original number. Ex – 145.

Special Number

To check for special number in Java, we need first calculate the factorial of its digits and then sum it up. To do this we will extract each digits using modulus (%) by 10 and then after computing factorial of it, will sum it up.


Find all Special Numbers in the Interval in Java

For this, we will implement the same method as used in the above program but instead of calculating factorial of each of the digits of individual numbers, we will store the factorial of 0 to 9 in the array and will use it accordingly.

For example factorial of 5 would be array[5], similarly factorial of 3 would be array[3].

Let’s start it by taking input of the lower and upper value of the interval.


If you have any doubts and suggestion then comment below.

Leave a Reply