combination from factorial via IntStream - Java Lambda Stream

Java examples for Lambda Stream:IntStream

Description

combination from factorial via IntStream

Demo Code


    //package com.java2s;
    import java.util.stream.IntStream;

    public class Main {
        public static int combination(final int n, final int k) {
            return factorial(n) / (factorial(k) * factorial(n - k));
        }/*from  w w w .  j av a2 s. c  om*/

        public static int factorial(final int n) {
    return IntStream.rangeClosed(1, n).reduce((x, y) -> x * y).getAsInt();
}
    }

Related Tutorials