This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Originally posted by Doug Cates: Can anyone explain to me how to solve a function for a given value,...
I left a few things out, but this is called a recursive function - and will be a standard introductory demo program.
What are you trying to accomplish ?
Joined: Jun 16, 2007
The assignment is to solve the function for given variables. I don't really understand exactly how to plug them back in and arrive at a numerical answer. Thanks
Joined: Sep 17, 2006
How much experience coding do you have ? You answered my question, in the manner that tells me how to go about responding - but you need to tell me if you are past the get-going of coding a sample program, compiling it and then running it.
There are later ways of doing this, but what I always do is just place a main() in the class and then run it as a program. To get data out, I usually write to a file to avoid some other issues, but one can put up a Graphical User Interface - which gets distracting if you have not written five or ten programs effectively. It helps if you tell me what editor you are using. This may be an IDE - Integrated Development Environment, which ususually have editors built in. Sometimes they will run the program you have compiled, but that can become a complexity in it's self. [ June 18, 2007: Message edited by: Nicholas Jordan ]
I think you're asking how to work out the answer on paper, right? I can't offer you any especially handsome or formal way to do it; perhaps someone else would. But basically you can just think like a computer and walk through the code, a line at a time, writing down intermediate results. For example, for this function, you want to know func1(8, 3). So you'd ask "is either argument 1?" And the answer is no, so now you want func1(7, 2) + 3*func1(7,3). So you'd look at func1(7, 2) first, and ask if the arguments are 1. Nope, so now you want func1(6, 1) + 2*func1(6, 2) + 3*func1(7, 3). Again, take the first one. This time, one of the arguments [b]is[/i] 1, so you immediately substitute "1", and now you're looking for 1 + 2*func1(6, 2) + 3*func1(7, 3). After a few more steps, the middle term will be broken down, and then you'd go after the last one.