desislava_topuzakova

08. Factorial Division

Feb 7th, 2021
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Locale;
  2. import java.util.Scanner;
  3.  
  4. public class ProjectsCreation {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int number1 = Integer.parseInt(scanner.nextLine());
  8.         int number2 = Integer.parseInt(scanner.nextLine());
  9.         long factorial1 = calculateFactorial(number1);
  10.         long factorial2 = calculateFactorial(number2);
  11.         double result =  factorial1 * 1.0  / factorial2;
  12.         System.out.printf("%.2f", result);
  13.  
  14.     }
  15.  
  16.     static long calculateFactorial(int number)  {
  17.         long fact = 1;
  18.         for (int i = 1; i <= number ; i++) {
  19.             fact = fact * i;
  20.         }
  21.         //1 * 2 * 3 * 4 * 5
  22.         return fact;
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment