Advertisement
psi_mmobile

Untitled

Aug 27th, 2022
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         int factorial = 1;
  5.         String input = scanner.nextLine();
  6.         int number = 1;
  7.         int endSum = 0;
  8.         int inputInt = Integer.valueOf(input);
  9.         String result = null;
  10.         for (int p = 0; p < input.length();p++) {
  11.             number = Character.getNumericValue(input.charAt(p));
  12.             for (int i = 1; i <= number; i++) {
  13.                 factorial=factorial* i;
  14.             } // calculate a singular digit factorial
  15.             endSum+=factorial;
  16.             factorial = 1; // reset single digit factorial calculcation for next digit
  17.         }
  18.         if (endSum == inputInt) {
  19.             result = "yes";
  20.         } else {
  21.             result = "no";
  22.         }
  23.         System.out.println(result);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement