mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-10 21:43:15 +08:00
Merge pull request #351 from LeeChungWan/master
Updated krishnamurthy.java
This commit is contained in:
@ -1,23 +1,20 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
class krishnamurthy
|
||||
{
|
||||
int fact(int n)
|
||||
{
|
||||
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[])
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
while (a > 0) {
|
||||
b = a % 10;
|
||||
s = s + fact(b);
|
||||
a = a / 10;
|
||||
@ -26,5 +23,6 @@ class krishnamurthy
|
||||
System.out.print(n + " is a krishnamurthy number");
|
||||
else
|
||||
System.out.print(n + " is not a krishnamurthy number");
|
||||
sc.close();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user