aneliabogeva

StrongNumber

Jan 15th, 2023
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package main.conditionalStatementsAndLoopsCompete;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class StrongNumber {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String number = scanner.nextLine();
  9.         int factorial = 1;
  10.         int sum = 0;
  11.  
  12.         for (int i = 0; i < number.length(); i++) {
  13.             char ch = number.charAt(i);
  14.             int newFactorial = Integer.parseInt(String.valueOf(ch));
  15.             for (int j = 1; j <= newFactorial; j++) {
  16.                 factorial *= j;
  17.             }
  18.  
  19.             if (newFactorial == 0) {
  20.                 sum += 1;
  21.             } else {
  22.                 sum += factorial;
  23.                 factorial = 1;
  24.             }
  25.         }
  26.         if (Integer.parseInt(number) == sum) {
  27.             System.out.println("yes");
  28.         } else {
  29.             System.out.println("no");
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment