I have spent a couple of minutes recreating the formula nCr = n!/r!(n-r)! to find the number of combinations in an array. So far I have been succesful in implementing this formula, but I'm seeking alternative methods of using such a formula. Here is my code:
import java.util.Scanner;
public class Factorial {
    public static void main(String[] args) {
        System.out.println("Enter Num");
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        long f = 1;
        for(int i = 1; i <= num; ++i)
        {
            f *= i;
        }
        System.out.println("Factorial of " +num +" = " +f);
        System.out.println("Enter r");
        int r = sc.nextInt();
        int bracket = num-r;
        int f2 = 1;
        int rf = 1;
        for(int i = 1; i <= r; ++i)
        {
            rf *= i;
        }
        for(int i = 1; i <= bracket; ++i)
        {
            f2 *= i;
        }
        long ans = f/(rf*f2) ;
        System.out.println(num+"C"+r +" = "+ans);
    }
}