-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay15.java
More file actions
63 lines (43 loc) · 1.08 KB
/
Day15.java
File metadata and controls
63 lines (43 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Day 15 coding Statement : Write a program to identify if the number is Strong number or not
Description
Get a number as input from user and then check whether that number is a strong number or not. A number is said to be strong number if the sum of the factorial of each digit in the number is same as that of the number.
E.g. let the number be 145
Here 1! + 4! + 5! is 1 + 24 + 120 which is equal to 145 itself.
Input
121
Output
Not a strong number
Input
2
Output
Strong number
*/
import java.util.*;
public class Day15
{ public static int factorial(int n){
int fact=1;
for(int i=1;i<=n;i++){
fact=fact*i;
}
return fact;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number : ");
int n=sc.nextInt();
int val=n;
int rev=0;
int sum=0;
while(n>0)
{
int rem=n%10;
sum=sum+factorial(rem);
n=n/10;
}
if(sum==val)
System.out.println("It is a Strong number. ");
else
System.out.println("It is not a strong number.");
}
}