Updated krishnamurthy.java

This commit is contained in:
unknown 2017-12-11 13:36:42 +09:00
parent 970be086b7
commit 5c10b903ff

View File

@ -1,30 +1,28 @@
import java.util.Scanner;
class krishnamurthy
{
int fact(int n)
{
int i,p=1;
for(i=n;i>=1;i--)
p=p*i;
class krishnamurthy {
static int fact(int n) {
int i, 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,b,s=0;
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int a, b, 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;
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");
if (s == n)
System.out.print(n + " is a krishnamurthy number");
else
System.out.print(n+" is not a krishnamurthy number");
System.out.print(n + " is not a krishnamurthy number");
sc.close();
}
}