Merge pull request #351 from LeeChungWan/master

Updated krishnamurthy.java
This commit is contained in:
Varun Upadhyay 2017-12-10 21:08:26 -08:00 committed by GitHub
commit 6498d4a937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,30 +1,28 @@
import java.util.Scanner; import java.util.Scanner;
class krishnamurthy class krishnamurthy {
{ static int fact(int n) {
int fact(int n) int i, p = 1;
{ for (i = n; i >= 1; i--)
int i,p=1; p = p * i;
for(i=n;i>=1;i--) return p;
p=p*i; }
return p;
} public static void main(String args[]) {
public static void main(String args[]) Scanner sc = new Scanner(System.in);
{ int a, b, s = 0;
Scanner sc=new Scanner(System.in); System.out.print("Enter the number : ");
int a,b,s=0; a = sc.nextInt();
System.out.print("Enter the number : "); int n = a;
a=sc.nextInt(); while (a > 0) {
int n=a; b = a % 10;
while(a>0) s = s + fact(b);
{ a = a / 10;
b=a%10; }
s=s+fact(b); if (s == n)
a=a/10; System.out.print(n + " is a krishnamurthy number");
} else
if(s==n) System.out.print(n + " is not a krishnamurthy number");
System.out.print(n+" is a krishnamurthy number"); sc.close();
else }
System.out.print(n+" is not a krishnamurthy number");
}
} }