Write a program for the given number is strong number (or) not?

Given Number is Strong number or Not Program in java:

Sum of the factorial of its digits is equal to the given number then the number is known as Strong number.
For example 145 is a strong number
= 1! + 4! + 5!
1+(4*3*2*1)+(5*4*3*2*1)
= 1 + 24 + 120
= 145

The following program is the given number is a strong number or not.

import java.util.Scanner;

/**
*
* @author Hi
*/
public class strong {
public static void main(String args[]){
int n,sum=0,r,t;
System.out.println(“enter the n value : “);
Scanner k= new Scanner(System.in);
n=k.nextInt();
t=n;
while(n!=0){
r=n%10;
int f=1;
for(int i=1;i<=r;i++){
f=f*i;
}
sum=sum+f;
n=n/10;

}
if(sum==t)
System.out.println(“the given number is the strong number”);
else
System.out.println(“the given number is not the strong number”);

}

}

output:
enter the n value :
145
The given number is a strong number

Related Programs Below:
Write a program the given number is even or odd in java?
Write a program for the given number is Fibonacci or not in java?
Prime numbers in Java?
Palindrome number Program in java?
Armstrong Number or not in Java?
Write a program for the given number is strong Number or Not  in java?
Write a program swapping two numbers without using third variable in java ?
Swapping of two numbers using third variable in java?

Leave a Reply

Your email address will not be published.