Advertisement
CoineTre

JF-ExcMethods08.Factorial Division

Feb 12th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exc8FactorialDivision {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int first = Integer.parseInt(scanner.nextLine());
  7.         int second = Integer.parseInt(scanner.nextLine());
  8.         long firstFactorial = getFactorialResult(first);
  9.         long secondFactorial = getFactorialResult(second);
  10.         System.out.printf("%.2f",(firstFactorial*1.0 / secondFactorial));
  11.     }
  12.  
  13.     private static long getFactorialResult(int n) {
  14.         long factorial = 1;
  15.         for (int i = 1; i <= n; i++) {
  16.             factorial = factorial * i;
  17.         }
  18.         return factorial;
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement