1

Can anyone help me with this example? The recursion can be in the constructor but not outside. import

class recursion {
    int factorial_imp(int i) {
        if (i == 1) return 1;
        else return i * factorial_imp(i - 1);
    }
    Function < Integer, Integer > factorial_lambda;
    public static void main(String[] args) {
        new recursion();
    }
    public recursion() {
        factorial_lambda = (i) -> {
            if (i == 1) return 1;
            else return i * (factorial_lambda.apply(i - 1));
        };
        System.out.println(factorial_imp(5));
        System.out.println(factorial_lambda.apply(5));
    }
}
3
  • 4
    What is the problem you're having? Commented Nov 23, 2015 at 19:43
  • 1
    @BenM. Forming a well-phrased question, apparently. Commented Nov 23, 2015 at 19:44
  • 1
    @BenM. the problem is people posting duplicated questions and other people thinking OP has discovered something new. Commented Nov 23, 2015 at 19:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.