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