This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes dumb question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "dumb question" Watch "dumb question" New topic
Author

dumb question

Doug Cates
Greenhorn

Joined: Jun 16, 2007
Posts: 7
Can anyone explain to me how to solve a function for a given value, for example:

for value of func1(8,3)?

For the record, I changed the values so you won't be just doing my hopmework for me.

Thank you
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
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 ?
Doug Cates
Greenhorn

Joined: Jun 16, 2007
Posts: 7
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
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
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 ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Doug --

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.


[Jess in Action][AskingGoodQuestions]
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Ahhh,....yes.

And when you get ready to use the computer to run the steps Ernest Friedman-Hill describes, remember that computers are really good at doing thousands of computations a second.
 
 
subject: dumb question
 
Similar Threads
Alpha beta pruning with negamax
|| operand
URL encoding and arguments
TicTacToe Game..
question on iteration