Special Number (Krishnamurthy Number) Program in Java
A special number, also called a Krishnamurthy number, is equal to the sum of the factorials of its digits, like 145. Java program for ICSE with output.
A number is known as Special number when sum of the factorial of digits is equal to the original number. It is also known as Krishnamurthy number. For example 145
1!+4!+5!= 1+24+120= 145
For the factorial program click the link
Factorial of a number :Unleashed
Write a program to accept a number and print whether it is a special number or not.
import java.io.*;
class SpecialNumber //one when the sum of factorial of its digits is = the number itself e.g., 145
{
public static void main()throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int n=Integer.parseInt(br.readLine());
int fact=1;
int num=n;
int sum=0;
while(n!=0) {
int rem=n%10;
for(int i=1;i<=rem;i++)
{
fact*=i;
}
sum+=fact;
fact=1;
n=n/10;
}
if(num==sum)
{
System.out.println("It is a special number");
}
else
{
System.out.println("Its not a special number");
} } }Output:
Enter a number
145
It is a special number
For videos regarding java programming watch the video
https://www.youtube.com/watch?v=QZKcULOC4lg
For more number programs click the given link:
Masterful Important Number programs ICSE part-3
Other special numbers in the ICSE syllabus, such as Armstrong, spy, neon, Disarium and pronic numbers, are covered with one program that checks them all in Special Number Programs in Java for ICSE.
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.