package Lambda;
public interface NumericFunc {
int func(int n);
}
class BlockLambdaDemo{
public static void main(String args[]){
NumericFunc factorial = (n) -> {
int result = 1;
for(int i = 1; i <= n; i++)
result = i * result;
return result;
};
System.out.println("Факториал числа 3 равен " + factorial.func(3));
System.out.println("Факториал числа 5 равен " + factorial.func(5));
}
}
System.out.println("Факториал числа 3 равен " + factorial.func(20));
System.out.println("Факториал числа 5 равен " + factorial.func(46));
Function<Integer, Integer> factorial =
(n) -> IntStream.rangeClosed(1, n)
.reduce((left, right) -> left * right)
.getAsInt();
System.out.println(factorial.apply(5));