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  ww w  .  j  av a  2s  .co  m

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

Related Tutorials