Didart

Strong Number

Sep 20th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. package src;
  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.  
  9.         int number = Integer.parseInt(scanner.nextLine());
  10.         int startNumber = number;
  11.         int sumFactDigit = 0;
  12.  
  13.         while (number != 0) {
  14.             int lastDigit = number % 10;
  15.             int fact = 1;
  16.             for (int i = 1; i <= lastDigit ; i++) {
  17.                fact = fact * i;     //fact * novoto chislo
  18.             }
  19.             sumFactDigit += fact;
  20.             number = number / 10;
  21.         }
  22.  
  23.         if (startNumber == sumFactDigit) {
  24.             System.out.println("yes");
  25.         } else {
  26.             System.out.println("no");
  27.         }
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment