SHARE
TWEET

Strong Number

elvirynwa Jan 24th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class StrongNumber {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String inputNumber = scanner.nextLine();
  8.  
  9.         long sum = 0;
  10.         for (int i = 0; i < inputNumber.length(); i++) {
  11.             int number = Integer.parseInt(String.valueOf(inputNumber.charAt(i)));
  12.  
  13.             int factorial = 1;
  14.             for (int j = 1; j <= number; j++) {
  15.                 factorial *= j;
  16.             }
  17.             sum += factorial;
  18.         }
  19.         System.out.println(inputNumber.equals(String.valueOf(sum)) ? "yes" : "no");
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top