You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You received the incremen() error because there does not exist any such method in the file Counter.java . However, it does contain the method increment() which is used to increment the value of the instance variable count used to measure the number of recursive calls. Therefore, the command
c.increment()
increments the value of the instance variable count associated with the object c.
The result that you obtained for b is correct but not for c. This is because the line
StdOut.println(c); in your code
prints out the local value of c in your main() method rather than the value of c local to the binomial() method even though it is the latter value that you want. Since, the value of c in your main method has been set to 0, that is the value which is displayed.
On the other hand, the line
StdOut.println(c); in the original code
calls the toString() method associated with the Counter object c which prints the current value of count, which is continuously incremented and stored in the Counter object c. Since this value is 1223 at the end of the recursive calls, that is the value displayed
In the Ex_1_1_27a.java binomial() function, I test the code,but there is a error :
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:
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 !
The text was updated successfully, but these errors were encountered: