Answer the question
In order to leave comments, you need to log in
How to fix compilation of java programs in NetBeans?
Initially, this program compiles normally:
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));
Answer the question
In order to leave comments, you need to log in
1) install Intellij idea
2) packages are called with a small letter
3) the written code does not make sense, you declared an interface and created an anonymous implementation of it instead of just declaring a static function
4) and if you really want to solve problems in a functional style using java 8 could do something like this:
Function<Integer, Integer> factorial =
(n) -> IntStream.rangeClosed(1, n)
.reduce((left, right) -> left * right)
.getAsInt();
System.out.println(factorial.apply(5));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question