Hello,
I'm testing CodeRunner on my server.
I created a Java Program question as follows:
Write a method named factorial that takes a positive integer n and returns n! where n! = n * (n-1) * (n-2) * ... * 2 * 1
Example: factorial(3) will return 6
A possible solution to the problem is:
import java.util.Scanner;
public class Test
{
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(factorial(n));
}
public static int factorial(int n)
{
int f = 1;
while(n > 1)
{
f = f * n;
n--;
}
return f;
}
}
Moodle saves the program and Coderunner can execute the program with no problems.
However when a recursive solution is given for the factorial method like below:
public static int factorial(int n)
{
if(n > 1)
{
return n * factorial(n-1);
}
else
{
return 1;
}
}
moodle returns a 403 error and the program fails to save.
I've pasted the above code into some of the sample questions and coderunner is able to compile and run the code.
I'm using moodle 3.5 and coderunner 3.5.1
Any thoughts of what might be causing the problem?
Thanks
Jeffrey