Solved ProgramsICSEClass 10Computer Applications

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.

Updated
Solved Programs

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.