Java Program for Special Number3 min read

Here we will learn how to do programming on Special Number. We will start by understanding, what is Special Number and solve the following two questions on special Numbers in Java.

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.

Also before we begin, if you do not know the working idea of for, while loop and if-else statement in java then click the link below and learn about them as this program uses them.

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 the % 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. The program takes two inputs from the user Lower Value and Upper-Value inputs and runs the loop for those values. Also if no special number is found between the upper and lower value, the 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.


MORE

C Program to Check whether the entered character is capital, small letter, digit or special character

In this tutorial, we will write a program to check whether the entered character is capital, small letter, digit or any special character using C …
Read More

C Program to Check Armstrong Number

In this C programming example, we will write a program to check Armstrong Number in C. We will start with Armstrong Number. Before that, you …
Read More

C Program to Generate Random numbers within a Range

In this tutorial, you will learn to generate random numbers within a range in C programming. But before that, you may go through the topic …
Read More

C Program to Generate Random Numbers

In this C program section, we will learn how to generate random numbers in C programming. Let us start with random numbers. What is Randon …
Read More

Keith Number in Java

In this java programming tutorial, you will learn about Keith Number and its implementation in java. It is frequently asked in Java coding. What is …
Read More

Fascinating Number in Java

In this java program tutorial, we will learn about the Fascinating Number and its implementation through Java. We will check whether the number Fascinating Number …
Read More