Strong Number

 Strong Number

Problem Description


Java Program to check for strong number


Sample Input:

Input : n = 145

Output : Yes

Sum of digit factorials = 1! + 4! + 5!

= 1 + 24 + 120

= 145


Solution,


import java.util.Scanner;

import java.io.*;

public class TestClass {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

int ON=n;

int sum=0;

while(n!=0)

{

int fact=1;

int i=1;

int r=n%10;

while(i<=r)

{

  fact=fact*i;

  i++;

}

  sum=sum+fact;

  n=n/10;

}

if(sum == ON)

System.out.println(" Yes");

else

System.out.println("No");

}

}


Post a Comment

0 Comments