desislava_topuzakova

5. Деление на факториел

Feb 13th, 2022
1,336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package Methods;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Factorial_05 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int firstNumber = Integer.parseInt(scanner.nextLine());
  9.         int secondNumber = Integer.parseInt(scanner.nextLine());
  10.  
  11.         //факториел на първото
  12.         //факториел на второто
  13.         //факториел на първото / факториел на второто -> печатам
  14.         System.out.printf("%.2f", factorial(firstNumber) / factorial(secondNumber));
  15.     }
  16.  
  17.     public static double factorial (int number) {
  18.         double fact = 1;
  19.         for (int i = 1; i <= number ; i++) {
  20.             fact = fact * i;
  21.         }
  22.         return fact;
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment