Didart

Factorial Division

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