Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Permutations {
- public static void main(String []args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter first number: ");
- int inputA = scan.nextInt();
- System.out.print("Enter second number: ");
- int inputB = scan.nextInt();
- System.out.println(permute(inputA, inputB));
- }
- public static int permute(int a, int b) {
- if (a < b) throw new IllegalArgumentException("First number must be >= second number.");
- return getFactorial(a) / getFactorial(a-b);
- }
- public static int getFactorial(int a) {
- if (a < 0) throw new IllegalArgumentException("Number must be >= 0");
- return a == 0 || a == 1 ? 1 : a * getFactorial(a-1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement