Skip to content

Commit 5c10b90

Browse files
committed
Updated krishnamurthy.java
1 parent 970be08 commit 5c10b90

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

Others/krishnamurthy.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import java.util.Scanner;
22

3-
class krishnamurthy
4-
{
5-
int fact(int n)
6-
{
7-
int i,p=1;
8-
for(i=n;i>=1;i--)
9-
p=p*i;
10-
return p;
11-
}
12-
public static void main(String args[])
13-
{
14-
Scanner sc=new Scanner(System.in);
15-
int a,b,s=0;
16-
System.out.print("Enter the number : ");
17-
a=sc.nextInt();
18-
int n=a;
19-
while(a>0)
20-
{
21-
b=a%10;
22-
s=s+fact(b);
23-
a=a/10;
24-
}
25-
if(s==n)
26-
System.out.print(n+" is a krishnamurthy number");
27-
else
28-
System.out.print(n+" is not a krishnamurthy number");
29-
}
3+
class krishnamurthy {
4+
static int fact(int n) {
5+
int i, p = 1;
6+
for (i = n; i >= 1; i--)
7+
p = p * i;
8+
return p;
9+
}
10+
11+
public static void main(String args[]) {
12+
Scanner sc = new Scanner(System.in);
13+
int a, b, s = 0;
14+
System.out.print("Enter the number : ");
15+
a = sc.nextInt();
16+
int n = a;
17+
while (a > 0) {
18+
b = a % 10;
19+
s = s + fact(b);
20+
a = a / 10;
21+
}
22+
if (s == n)
23+
System.out.print(n + " is a krishnamurthy number");
24+
else
25+
System.out.print(n + " is not a krishnamurthy number");
26+
sc.close();
27+
}
3028
}

0 commit comments

Comments
 (0)