forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKrishnamurthy.java
More file actions
38 lines (34 loc) · 836 Bytes
/
Krishnamurthy.java
File metadata and controls
38 lines (34 loc) · 836 Bytes
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
package com.thealgorithms.others;
import java.util.Scanner;
final class Krishnamurthy {
private Krishnamurthy() {
}
static int fact(int n) {
int i;
int p = 1;
for (i = n; i >= 1; i--) {
p = p * i;
}
return p;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a;
int b;
int s = 0;
System.out.print("Enter the number : ");
a = sc.nextInt();
int n = a;
while (a > 0) {
b = a % 10;
s = s + fact(b);
a = a / 10;
}
if (s == n) {
System.out.print(n + " is a krishnamurthy number");
} else {
System.out.print(n + " is not a krishnamurthy number");
}
sc.close();
}
}