Java Program for Special Number

Question:
1. Write a program in Java to check whether a number is Special or not.
2. Write a Java Program to find all special numbers between the interval.

What is a Special Number?

A special number is a number whose sum of the factorial of its digits is equal to the original number. Example: 145 is a special number.

Java Special Number

Java Program to check whether a number is Special or not.

To check for a special number, we take the number from the user, then separate the digits using % operator and then calculating the factorial of that individual digits. At last, add the digits and check if it’s equal to the original number and print the result accordingly as shown in the following program.

Source Code:

The output of special number in Java.


Java Program to find all the special numbers between the interval.

In this program, we have created a different function to calculate the sum of the digit and factorial of a number. Program takes two input from the user Lower Value and Upper Value inputs and run the loop for those value. Also if no special number is found between the upper and lower value, program prints no value as shown in the program.

We have use boolean value to check if at-least one value is found or not and perform accordingly.

Source Code:

The output of special number.

Java Programs