Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Methods_Exercise;
- import java.util.Scanner;
- public class FactorialDivision_08 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int firstNumber = Integer.parseInt(scanner.nextLine());
- int secondNumber = Integer.parseInt(scanner.nextLine());
- //факториел на първото число
- long firstNumberFactorial = calculateFactorial(firstNumber);
- //факториел на второто число
- long secondNumberFactorial = calculateFactorial(secondNumber);
- //факториел1 / факториел2 -> печатаме
- double result = firstNumberFactorial * 1.0 / secondNumberFactorial;
- System.out.printf("%.2f", result);
- }
- private static long calculateFactorial (int number) {
- long fact = 1;
- for (int i = 1; i <= number ; i++) {
- fact = fact * i;
- }
- return fact;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment