Java Program to check Krishnamurthy Number3 min read

In this tutorial, we will learn about Krishnamurthy numbers and write a Krishnamurthy Number program in Java. We will write two programs for Krishnamurthy number in java.

Krishnamurthy Number

A number is said to be a Krishnamurthy Number if the sum of the factorial of all digits of a number is equal to the original number itself. Krishnamurthy Number is also known as Strong number and is frequently asked questions in interviews.


Input: 145
Output: Krishnamurthy Number
= 1! + 4! + 5!
= 1 + 24 + 120
= 145
= Original Number

Java Program to check Krishnamurthy Number


We have created two different user-defined functions, one to calculate the factorial of a number and another to check the number for Krishnamurthy which is a boolean function.

Java Program to check Krishnamurthy number within the given Range


As you can see, we did the same way by creating separate functions but here we took the user input for both the lower and upper range and called the function within those ranges to find all the possible Krishnamurthy number java.


C++ Structures

In the C/C++ programming language, the structure is user-defined data types that allow us to store the combination of different data types together. All the …
Read More

C++ Static Keyword

Static s a keyword in C++ that is when used with different types gives different meanings. static keyword can be used with variables in a …
Read More

C++ Templates

Templates in C++ are the powerful feature that allows us to write generic programs (generic classes and generic functions). A single class or function is …
Read More

C++ Friend Function

There are private and protected members in a class that is inaccessible from outside of the class, constituting one of the concepts of object-oriented programming …
Read More

this Pointer in C++

In C++, this is a keyword that refers to the current instance of a class and this pointer holds the address or points to the …
Read More

Inheritance in C++

Inheritance is one of the most important concepts of object-oriented programming. In C++, inheritance is the process of deriving the properties and behaviors of one …
Read More