From 5c10b903ffb6c99d32801c07824918d41f8c8550 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 11 Dec 2017 13:36:42 +0900 Subject: [PATCH] Updated krishnamurthy.java --- Others/krishnamurthy.java | 52 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/Others/krishnamurthy.java b/Others/krishnamurthy.java index 66685bcc..52480eb0 100644 --- a/Others/krishnamurthy.java +++ b/Others/krishnamurthy.java @@ -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; - return p; - } - 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; - } - if(s==n) - System.out.print(n+" is a krishnamurthy number"); - else - System.out.print(n+" is not a krishnamurthy number"); - } +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; + 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(); + } }