# Write an expression that prints "special number" if specialnum is -99, 0, or 44.

8 views

Problem :

Write an expression that prints "special number" if specialnum is -99, 0, or 44.

Solution :

A Special Number is also called as Krishnamurthy number and Strong number.

The Number is called special number when the sum of the factorial of its digits

is equal to the number itself.

Please find below the examples of the numbers which are Special

`Number to be checked : 145 `
`1! + 4! + 5! = 1 + 24 + 120 = 145   // 145 is the Special Number`
`Number to be checked : 2 `
`2!  = 2 = 2   // 2 is the Special Number`
```Please find below the examples of numbers which are NOT the Special number

Number to be checked : 35```

3! + 5! = 6 + 120 = 126   // 35 is NOT the Special Number

Number to be checked : 105

1! + 0! + 5! = 1 + 1 + 120 = 122   // 105 is NOT the Special Number

` `

``````import java.util.*;

public class SpecialNumberJava

{

public static void main(String args[])

{

Scanner sc =new Scanner(System.in);

int no=sc.nextInt();

int check=no,mod=0,fact=1,sum=0;

while(no!=0)

{

mod=no%10;

no=no/10;

fact=1;

for(int i=mod;i>0;i--)

{

fact=fact*i;

}

sum=sum+fact;

}

if(check==sum)

{

System.out.println("The number is special number:"+sum);

}

else

{

System.out.println("The number is not special number:"+sum);

}

}

}``````

by (34.3k points)