I am trying to understand a block of code i have how exactly it works. My code is an example of recursion and try to calculate the chance of a number as a number of a nth dice rolling outcome. My code is the following:
public static double f(int sum, int r) {
if (r== 0) {
if (pr(s) ){
return 1;
}
else
return 0;
}
double rsum = 0;
for (int i = 1; i <= 6; i++) {
rsum += f(sum + i, r- 1)/6.0;
}
return rsum;
}
I struggle to understand how the recursion exactly is working and if I am doing what I am suppose to. Why sum takes values beyond six.
EDIT: in the debugging that it goes like that: f3(1,2) -> f(2,1) and then instead of f(3,0) it goes again to ev3(2,1) any idea why this is happening?