Skip to content

Commit 6498d4a

Browse files
authored
Merge pull request TheAlgorithms#351 from LeeChungWan/master
Updated krishnamurthy.java
2 parents e72bf4c + 5c10b90 commit 6498d4a

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy