factorial by IntStream - Java Lambda Stream

Java examples for Lambda Stream:IntStream

Description

factorial by IntStream

Demo Code


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

    public class Main {
        public static int factorial(final int n) {
    return IntStream.rangeClosed(1, n).reduce((x, y) -> x * y).getAsInt();
}
    }// w  ww . j  av a2 s  .  c o  m

Related Tutorials