Simple testcase factorial always returns 0
In Simple.java the factorial function always return 0.
public static int factorial(int n) {
int m = n;
while (n-- > 0) {
m *= n;
}
return m;
}
Since the increment is applied after the comparison, the last run of the while loop results in m*=0;
The condition should be --n > 0
.