Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SoftUni {
- public static int factorial(int n){
- if(n == 0){
- return 1;
- }
- else{
- return n*factorial(n-1);
- }
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter your number and I will check if it is a string number: ");
- //A number is strong if the sum of the Factorial of each digit is equal to the number
- int number = Integer.parseInt(sc.nextLine());
- int check = number;
- int sum = 0;
- while(number > 0){
- int current = number%10;
- sum += factorial(current);
- number /= 10;
- }
- if(check == sum){
- System.out.println( sum + " is a strong number!");
- }
- else{
- System.out.println(check + " is not a strong number!");
- }
- }
- }
Add Comment
Please, Sign In to add comment