File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ public class SpecialNo {
4+ public static void main (String [] args ) {
5+ Scanner in =new Scanner (System .in );
6+ int num , digit , sum =0 , temp ;
7+
8+
9+ System .out .println ("Enter any number" ); // Input the number from user
10+ num = in .nextInt ();
11+ temp = num ;
12+
13+
14+ while (temp != 0 ){
15+ digit = temp %10 ; //Find the factorial of its digits.
16+ sum += factorial (digit ); // Add all the factorial.
17+ temp = temp /10 ;
18+ }
19+
20+
21+ if (sum == num ) //Check if the computed sum is equal to the original number.
22+ System .out .println ("Given number is Special Number" );
23+ else
24+ System .out .println ("Not a Special Number" );
25+
26+ }
27+
28+
29+ private static int factorial (int n ){ //function to compute the factorial of the digits
30+ int f =1 ;
31+ for (int i =2 ; i <=n ; i ++){
32+ f = f *i ;
33+ }
34+ return f ;
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments