forked from Haresh1204/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strongNumberCheck.java
57 lines (37 loc) · 1.03 KB
/
strongNumberCheck.java
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
import java.util.Scanner;
public class StrongNumberCheck {
public static boolean isStrong(int number) {
int sum = 0, lastDigit = 0;
int tempNum = number;
while(tempNum != 0) {
lastDigit = tempNum % 10;
sum += factorial(lastDigit);
tempNum /= 10;
}
if(sum == number)
return true;
return false;
}
public static long factorial(int n) {
long fact = 1;
for(int i=1; i<=n; i++) {
fact *= i;
}
return fact;
}
public static void main(String[] args) {
int number = 0;
boolean result = false;
Scanner scan = new Scanner(System.in);
System.out.print("Enter an integer number:: ");
number = scan.nextInt();
result = isStrong(number);
if(result)
System.out.println(number +
" is a strong number.");
else
System.out.println(number +
" is not a strong number");
scan.close();
}
}