Advertisement
vkarakolev

Untitled

Nov 3rd, 2020
77
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.Scanner;
  2.  
  3. public class E08_FactorialDivision {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int firstNum = scanner.nextInt();
  7.         int secondNum = scanner.nextInt();
  8.  
  9.         double result = (double) getFactorial(firstNum) / getFactorial(secondNum);
  10.         System.out.printf("%.2f", result);
  11.  
  12.     }
  13.  
  14.     static int getFactorial(int number) {
  15.         int factorial = number;
  16.         if(number == 0){
  17.             factorial = 1;
  18.         } else if (number == 1) {
  19.             factorial = 1;
  20.         } else {
  21.             for (int i = 1; i < number; i++) {
  22.                 factorial *= number - i;
  23.             }
  24.         }
  25.  
  26.         return factorial;
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement