-
Notifications
You must be signed in to change notification settings - Fork 953
Open
Description
In the Ex_1_1_27a.java binomial() function, I test the code,but there is a error :
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method incremen() is undefined for the type Counter
In your program, the incremen() is undefined, so, how can the this program run successfully?
I know the Counter c is used to cumulative the number of recursive calls, but can't understand why use the function c.incremen().
I think now that c is used to cumulative the number of recursive calls, I use this program:
public static double binomial( int n, int k, double p, int c) {
if ( n == 0 && k == 0) {
return 1.0;
}
if ( n < 0 || k < 0) {
return 0.0;
}
c++;
return (1.0 - p) * binomial( n - 1, k, p, c) + p * binomial( n - 1, k - 1, p, c);
}
public static void main(String[] args) {
int n = Integer.parseInt(args[0]),
k = Integer.parseInt(args[1]);
double p = Double.parseDouble(args[2]);
int c = 0;
double b = binomial(n, k, p, c);
StdOut.println(b);
StdOut.println(c);
}I test 10 5 0.5, but I get the result: 0.24609375 0.
I hope to help me Solve this doubt,thanks a lot !
Metadata
Metadata
Assignees
Labels
No labels